From: Michael Tremer Date: Wed, 7 Dec 2016 21:11:16 +0000 (+0100) Subject: ui: Format bytes with proper whitespace and decimal points X-Git-Tag: 0.9.28~1285^2~1385 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58462a80b57ebde04bcab7104d408cd13cc212dc;p=pakfire.git ui: Format bytes with proper whitespace and decimal points Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/ui/helpers.py b/src/pakfire/ui/helpers.py index 7d96cf1bf..102f2ca0f 100644 --- a/src/pakfire/ui/helpers.py +++ b/src/pakfire/ui/helpers.py @@ -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)