
On 09/03/2014 05:47 PM, CrÃstian Viana wrote:
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@linux.vnet.ibm.com> --- src/kimchi/model/storagevolumes.py | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py index fac34d5..d1a19ff 100644 --- a/src/kimchi/model/storagevolumes.py +++ b/src/kimchi/model/storagevolumes.py @@ -138,6 +138,9 @@ class StorageVolumesModel(object):
with contextlib.closing(urllib2.urlopen(url)) as response,\ open(file_path, 'w') as volume_file: + remote_size = response.info().getheader('Content-Length', '-') + downloaded_size = 0 + try: while True: chunk_data = response.read(DOWNLOAD_CHUNK_SIZE) @@ -145,6 +148,8 @@ class StorageVolumesModel(object): break
volume_file.write(chunk_data) + downloaded_size += len(chunk_data) + cb('downloading %s/%s' % (downloaded_size, remote_size))
Record only the values <downloaded_size>/<remote_size> so UI can use it as needed. And also translate the message to the selected language.
except Exception, e: raise OperationFailed('KCHVOL0007E', {'name': name, 'pool': pool_name,