diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-10 14:01:58 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-11 16:04:44 +0000 |
commit | 1e03a84261184efae8d3196784dc0241eae6199c (patch) | |
tree | a60e5934ab42008f3d9396ea321717e868f7d4f3 | |
parent | 4923dac4c5b67dc447cc562a4f3ca8380eafc0b2 (diff) | |
download | morph-1e03a84261184efae8d3196784dc0241eae6199c.tar.gz |
Fix the really cheesy progress meter for fetching artifacts
-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: |