[Bf-blender-cvs] [16da5d84c0c] soc-2017-package_manager: Wait until we've determined url is a real url to derive filenames from it

gandalf3 noreply at git.blender.org
Tue Aug 29 11:46:11 CEST 2017


Commit: 16da5d84c0c4d5d630c4d42085f108ed7e0a40f8
Author: gandalf3
Date:   Mon Aug 28 23:41:54 2017 -0700
Branches: soc-2017-package_manager
https://developer.blender.org/rB16da5d84c0c4d5d630c4d42085f108ed7e0a40f8

Wait until we've determined url is a real url to derive filenames from it

===================================================================

M	release/scripts/modules/bpkg/actions.py

===================================================================

diff --git a/release/scripts/modules/bpkg/actions.py b/release/scripts/modules/bpkg/actions.py
index 2d0e88d4a45..2dd2c0ab7c9 100644
--- a/release/scripts/modules/bpkg/actions.py
+++ b/release/scripts/modules/bpkg/actions.py
@@ -23,17 +23,7 @@ def download(url: str, destination: Path, progress_callback=None) -> Path:
 
     progress_callback(0)
 
-    # derive filename from url if `destination` is an existing directory, otherwise use `destination` directly
-    if destination.is_dir():
-        # TODO: get filename from Content-Disposition header, if available.
-        from urllib.parse import urlsplit, urlunsplit
-        parsed_url = urlsplit(url)
-        local_filename = Path(parsed_url.path).name or 'download.tmp'
-        local_fpath = destination / local_filename
-    else:
-        local_fpath = destination
-
-    log.info('Downloading %s -> %s', url, local_fpath)
+    log.info('Downloading %s ', url)
 
     # try:
     resp = requests.get(url, stream=True, verify=True)
@@ -49,6 +39,18 @@ def download(url: str, destination: Path, progress_callback=None) -> Path:
         log.info("Server responded 'Not Modified', not downloading")
         return None
 
+    # determine destination filename from url, but only after we've determined it works as a real url
+    # derive filename from url if given `destination` is an existing directory,
+    # otherwise use `destination` directly
+    if destination.is_dir():
+        # TODO: get filename from Content-Disposition header, if available.
+        from urllib.parse import urlsplit, urlunsplit
+        parsed_url = urlsplit(url)
+        local_filename = Path(parsed_url.path).name or 'download.tmp'
+        local_fpath = destination / local_filename
+    else:
+        local_fpath = destination
+
     try:
         # Use float so that we can also use infinity
         content_length = float(resp.headers['content-length'])



More information about the Bf-blender-cvs mailing list