diff options
Diffstat (limited to 'morphlib/remoteartifactcache.py')
-rw-r--r-- | morphlib/remoteartifactcache.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/morphlib/remoteartifactcache.py b/morphlib/remoteartifactcache.py index b4036385..2be4ba70 100644 --- a/morphlib/remoteartifactcache.py +++ b/morphlib/remoteartifactcache.py @@ -71,14 +71,16 @@ class RemoteArtifactCache(object): if not status_cb: return downloaded = min(downloaded, total) - if total is None: - status_cb(msg='Fetched %(downloaded).02fMB', - downloaded=downloaded / (1024 * 1024), + if total == 0: + status_cb(msg='%(file)s: Fetched %(d).02fMB', + file=remote_filename, + d=max(downloaded / (1024 * 1024), 0.01), chatty=True) else: - status_cb(msg='Fetched %(downloaded).02fMB of %(total).02fMB', - downloaded=downloaded / (1024 * 1024), - total=total / (1024 * 1024), + status_cb(msg='%(file)s: Fetched %(d).02fMB of %(t).02fMB', + file=remote_filename, + d=max(downloaded / (1024 * 1024), 0.01), + t=max(total / (1024 * 1024), 0.01), chatty=True) remote_url = self._request_url(remote_filename) @@ -87,10 +89,10 @@ class RemoteArtifactCache(object): try: response = requests.get(remote_url, stream=True) response.raise_for_status() - content_length = int(response.headers.get('content-length')) + content_length = int(response.headers.get('content-length', 0)) for i, chunk in enumerate(response.iter_content(chunk_size)): local_file.write(chunk) - show_status(i+1 * chunk_size, content_length) + show_status((i+1) * chunk_size, content_length) except requests.exceptions.HTTPError as e: logging.debug(str(e)) if e.response.status_code != 404 or error_if_missing: |