diff --git a/installsystems/progressbar/widgets.py b/installsystems/progressbar/widgets.py index f5ecf6126e0380e8fbcc6e5b1b7e5587066d98fa..0ec87aaab03c1e4a37d3ab0eee14a82a0661e672 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 4e54fbbf97b7e36b875d1d6d457ae139c7061987..80cd2ebeb29a1bf09f8312aee7b2882c402638ba 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() ]