]> git.ipfire.org Git - pakfire.git/commitdiff
ui: Format bytes with proper whitespace and decimal points
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 21:11:16 +0000 (22:11 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 21:11:16 +0000 (22:11 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/ui/helpers.py

index 7d96cf1bf0de4583246b7fbb891301b8e6664d19..102f2ca0f414c9606173a2538db364129ace3cdf 100644 (file)
@@ -49,14 +49,19 @@ def terminal_size():
        return int(cr[1]), int(cr[0])
 
 def format_size(s):
-       units = (" ", "k", "M", "G", "T")
+       units = (
+               "%4.0f ",
+               "%4.0fk",
+               "%4.1fM",
+               "%4.1fG",
+       )
        unit = 0
 
        while abs(s) >= 1024 and unit < len(units):
                s /= 1024
                unit += 1
 
-       return "%d%s" % (round(s), units[unit])
+       return units[unit] % s
 
 def format_time(s):
        return "%02d:%02d" % (s // 60, s % 60)