[Kimchi-devel] [PATCH 4/4] storagevolume: Add download progress to task
Crístian Viana
vianac at linux.vnet.ibm.com
Wed Aug 27 03:36:30 UTC 2014
The download operation can take a long time, so it's nice to have some
way to track its current progress.
Update the task's message with the number of bytes downloaded. The
format is "<bytes downloaded>/<total bytes>". If the number of bytes
cannot be read from the remote URL, <total bytes> will be "-".
Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
---
src/kimchi/model/storagevolumes.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
index dc19f4f..c044973 100644
--- a/src/kimchi/model/storagevolumes.py
+++ b/src/kimchi/model/storagevolumes.py
@@ -121,6 +121,8 @@ class StorageVolumesModel(object):
try:
response = urllib2.urlopen(url)
volume = open(target, 'w')
+ remote_size = response.info().getheader('Content-Length', '-')
+ downloaded_size = 0
while True:
chunk_data = response.read(chunk_size)
@@ -128,6 +130,8 @@ class StorageVolumesModel(object):
break
volume.write(chunk_data)
+ downloaded_size += len(chunk_data)
+ cb('downloading %s/%s' % (downloaded_size, remote_size))
except Exception, e:
raise OperationFailed('KCHVOL0007E', {'name': name,
'pool': pool_name,
--
1.9.3
More information about the Kimchi-devel
mailing list