summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-09-26 17:07:51 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2015-09-26 17:07:51 +0000
commit644fd0a12e75941e1d8fcdeeced9b3d87628696e (patch)
tree6ead5bf7503f8794713d83d263cfd602a37405aa
parent12f1f62cda10e9464b0a7498048257b69696e01a (diff)
downloadciat-tester-644fd0a12e75941e1d8fcdeeced9b3d87628696e.tar.gz
Show better progress when downloading images
-rwxr-xr-xtester19
1 files changed, 15 insertions, 4 deletions
diff --git a/tester b/tester
index 777ca96..da50541 100755
--- a/tester
+++ b/tester
@@ -262,15 +262,26 @@ def download_image(url):
path = str(uuid.uuid4()) + '-' + url.rpartition('/')[2]
print('[Local] Fetching: ' + url)
- response = urllib2.urlopen(url)
+ file_to_fetch = urllib2.urlopen(url)
+ total_file_size = int(file_to_fetch.info()['Content-Length'])
+
+ copied_size = 0
+ last_percentaje_shown = -1
CHUNK = 16 * 1024
with open(path, 'wb') as f:
- print('[Local] Progress:'),
+ print('[Local] Progress:')
while True:
- chunk = response.read(CHUNK)
+ chunk = file_to_fetch.read(CHUNK)
if not chunk: break
f.write(chunk)
- print('-'),
+ copied_size += len(chunk)
+ percentaje = (copied_size * 100) / total_file_size
+ if last_percentaje_shown < percentaje:
+ last_percentaje_shown = percentaje
+ print (" Copied %s %% - %s of %s bytes" % (percentaje,
+ copied_size,
+ total_file_size))
+
print('\n[Local] Saved as: ' + path)
return path