summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-24 09:14:03 +0100
committerRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-24 14:59:24 +0100
commit22cc88f921c6d92c1dd8a69d52af1d257941da4a (patch)
tree0b9226f4dc45cdd7cd354379565a0c078e6c9d4a
parent2b9dbe2547935f96b165e7f7d67e1af481bada40 (diff)
downloadvirt-bootstrap.git-22cc88f921c6d92c1dd8a69d52af1d257941da4a.tar.gz
virt-bootstrap.git-22cc88f921c6d92c1dd8a69d52af1d257941da4a.tar.xz
virt-bootstrap.git-22cc88f921c6d92c1dd8a69d52af1d257941da4a.zip
DockerSource: Fix formula of download progress
When downloading image with multiple layers, the download progress value of every following layer should not start from 0. If we have 10 layers, downloading each of them should increase the total download progress by 10%. Assuming that the download and extraction are 50/50 of the total work. Then, downloading each of 10 layers will increase the progress value with 5% of the total work. When all layers are downloaded the progress value should be 50%. However, with the current formula the progress value of each layer starts from 0%. (E.g. when downloading 2nd layer of 10 the download progress starts from 0% instead of 5%.) This bug can be seen when downloading images with multiple layers of large size. Example: virt-bootstrap docker://rails /tmp/foo --status-only
-rw-r--r--src/virtBootstrap/sources.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py
index 8800d72..898993d 100644
--- a/src/virtBootstrap/sources.py
+++ b/src/virtBootstrap/sources.py
@@ -225,7 +225,15 @@ class DockerSource(object):
total size of image layer.
Calculate percentage and update the progress of virt-bootstrap.
+
+ @param current_l: Number of currently downloaded layer
+ @param total_l: Total number of layers
+ @param line_split: A list with format:
+ [<d_size>, <d_format>, '/', <t_size>, <t_format>, <progress>]
+ Example:
+ ['5.92', 'MB', '/', '44.96', 'MB', '[===>-----------------]']
"""
+
if not (len(line_split) > 4 and isinstance(line_split, list)):
return
@@ -237,9 +245,13 @@ class DockerSource(object):
total_size = utils.size_to_bytes(t_size, t_format)
if downloaded_size and total_size:
try:
- self.progress(value=(50
- * downloaded_size / total_size
- * float(current_l)/total_l))
+ frac = float(1) / total_l
+ downloaded = float(downloaded_size) / total_size
+ layer_frac = float(max(0, current_l - 1)) / total_l
+
+ progress = 50 * (layer_frac + (frac * downloaded))
+
+ self.progress(value=progress)
except Exception:
pass # Ignore failures