Simplify fromhuman byte formatting
This commit is contained in:
parent
867ad1fc1b
commit
f3e9082376
|
@ -94,18 +94,11 @@ def format_bytes_tohuman(databytes):
|
||||||
return datahuman
|
return datahuman
|
||||||
|
|
||||||
def format_bytes_fromhuman(datahuman):
|
def format_bytes_fromhuman(datahuman):
|
||||||
databytes = ''
|
# Trim off human-readable character
|
||||||
for unit in sorted(unit_matrix, key=unit_matrix.get, reverse=True):
|
dataunit = datahuman[-1]
|
||||||
new_bytes = int(math.ceil(datahuman * unit_matrix[unit]))
|
datasize = int(datahuman[:-1])
|
||||||
# Round up if 5 or more digits
|
databytes = datasize * unit_matrix[dataunit]
|
||||||
if new_bytes < 9999:
|
return '{}B'.format(databytes)
|
||||||
# We can jump down another level
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
# We're at the end, display with this size
|
|
||||||
databytes = '{}{}'.format(new_bytes, unit)
|
|
||||||
|
|
||||||
return databytes
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Cluster search functions
|
# Cluster search functions
|
||||||
|
|
Loading…
Reference in New Issue