diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-09-18 14:50:29 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-09-18 14:50:29 +0200 |
commit | f16d560268134222c4f9068b63df2d4b29af714c (patch) | |
tree | d0508c651eb0555a23de6562a6c3e4be2f44a008 /fb.py | |
parent | e533fb2a3b34c4283a6228ecb2f4900369bed250 (diff) |
fb.py: Humanize sizes in history output
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'fb.py')
-rwxr-xr-x | fb.py | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -38,6 +38,22 @@ def print_table(table): print("| " + " | ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(line)) + " |") +def humanize_bytes(num): + suffix = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"] + boundary = 2048.0 + + for unit in suffix: + if abs(num) < boundary: + break + num /= 1024.0 + + if unit == "B": + format = "%.0f%s" + else: + format = "%.2f%s" + + return format % (num, unit) + @contextlib.contextmanager def make_temp_directory(): temp_dir = tempfile.mkdtemp() @@ -592,8 +608,8 @@ class FBClient: i['mimetype'], datetime.datetime.fromtimestamp(int(i['date'])).strftime(timeFormat), i['hash'], - i['filesize' - ]] for i in items] + humanize_bytes(int(i['filesize'])) + ] for i in items] print_table(itemsTable) def display_version(self): |