[util] generalize 'build_duration_func'
This commit is contained in:
@@ -209,11 +209,12 @@ def _hex_to_char(match):
|
||||
|
||||
def parse_bytes(value, default=0, suffixes="bkmgtp"):
|
||||
"""Convert a bytes-amount ("500k", "2.5M", ...) to int"""
|
||||
try:
|
||||
last = value[-1].lower()
|
||||
except Exception:
|
||||
if not value:
|
||||
return default
|
||||
|
||||
value = str(value).strip()
|
||||
last = value[-1].lower()
|
||||
|
||||
if last in suffixes:
|
||||
mul = 1024 ** suffixes.index(last)
|
||||
value = value[:-1]
|
||||
|
||||
Reference in New Issue
Block a user