remove 'unit' argument from 'util.format_value()'

This commit is contained in:
Mike Fährmann
2021-09-28 23:07:55 +02:00
parent 8c29a6e491
commit c22ff97743
3 changed files with 20 additions and 23 deletions

View File

@@ -294,15 +294,15 @@ class TerminalOutput(NullOutput):
def progress(self, bytes_total, bytes_downloaded, bytes_per_second):
if bytes_total is None:
print("\r {:>8} {:>10} \r".format(
util.format_value(bytes_downloaded, "B"),
util.format_value(bytes_per_second, "B/s"),
print("\r {:>7}B {:>7}B/s \r".format(
util.format_value(bytes_downloaded),
util.format_value(bytes_per_second),
), end="")
else:
print("\r{:>3}% {:>8} {:>10} \r".format(
print("\r{:>3}% {:>7}B {:>7}B/s \r".format(
bytes_downloaded * 100 // bytes_total,
util.format_value(bytes_downloaded, "B"),
util.format_value(bytes_per_second, "B/s"),
util.format_value(bytes_downloaded),
util.format_value(bytes_per_second),
), end="")

View File

@@ -91,15 +91,15 @@ def generate_token(size=16):
return binascii.hexlify(data).decode()
def format_value(value, unit="B", suffixes="kMGTPEZY"):
def format_value(value, suffixes="kMGTPEZY"):
value = format(value)
value_len = len(value)
index = value_len - 4
if index >= 0:
offset = (value_len - 1) % 3 + 1
return (value[:offset] + "." + value[offset:offset+2] +
suffixes[index // 3] + unit)
return value + unit
suffixes[index // 3])
return value
def combine_dict(a, b):