From 532267730c93545a998b42995a7d18e7bef98e4b Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Fri, 4 Nov 2011 14:27:02 +0100 Subject: [PATCH] Add a download size information on download progressbar --- installsystems/progressbar/widgets.py | 21 +++++++++++++++++++++ installsystems/tools.py | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/installsystems/progressbar/widgets.py b/installsystems/progressbar/widgets.py index f5ecf61..0ec87aa 100644 --- a/installsystems/progressbar/widgets.py +++ b/installsystems/progressbar/widgets.py @@ -140,6 +140,27 @@ class FileTransferSpeed(Widget): return self.format % (scaled, self.prefixes[power], self.unit) +class FileTransferSize(Widget): + 'Widget for showing the transfer size (useful for file transfers).' + + format = '%6.2f %s%s' + prefixes = ' kMGTPEZY' + __slots__ = ('unit', 'format') + + def __init__(self, unit='B'): + self.unit = unit + + def update(self, pbar): + 'Updates the widget with the current SI prefixed speed.' + + if pbar.currval < 2e-6: # =~ 0 + scaled = power = 0 + else: + power = int(math.log(pbar.currval, 1000)) + scaled = pbar.currval / 1000.**power + + return self.format % (scaled, self.prefixes[power], self.unit) + class AnimatedMarker(Widget): '''An animated marker for the progress bar which defaults to appear as if diff --git a/installsystems/tools.py b/installsystems/tools.py index 4e54fbb..80cd2eb 100644 --- a/installsystems/tools.py +++ b/installsystems/tools.py @@ -16,7 +16,8 @@ import time from subprocess import call, check_call, CalledProcessError import installsystems -from installsystems.progressbar import ProgressBar, Percentage, FileTransferSpeed +from installsystems.progressbar import ProgressBar, Percentage +from installsystems.progressbar import FileTransferSpeed, FileTransferSize from installsystems.progressbar import Bar, BouncingBar, ETA, UnknownLength from installsystems.tarball import Tarball from installsystems.printer import * @@ -72,7 +73,7 @@ class PipeFile(object): # init progress bar # we use 0 because a null file is cannot show a progression during write if self.size == 0: - widget = [ BouncingBar(), " ", FileTransferSpeed() ] + widget = [ FileTransferSize(), " ", BouncingBar(), " ", FileTransferSpeed() ] maxval = UnknownLength else: widget = [ Percentage(), " ", Bar(), " ", FileTransferSpeed(), " ", ETA() ] -- GitLab