Adjusted human_readable_size
* Now supports petabytes?
This commit is contained in:
parent
496b28c8a6
commit
73ca03da8e
1 changed files with 17 additions and 13 deletions
|
|
@ -307,20 +307,24 @@ def human_readable_size(size, decimals=0):
|
||||||
return '{size:>{width}} b'.format(size='???', width=width)
|
return '{size:>{width}} b'.format(size='???', width=width)
|
||||||
|
|
||||||
# Convert to sensible units
|
# Convert to sensible units
|
||||||
if size >= 1099511627776:
|
if size >= 1024 ** 5:
|
||||||
size /= 1099511627776
|
size /= 1024 ** 5
|
||||||
units = 'Tb'
|
units = 'PB'
|
||||||
elif size >= 1073741824:
|
elif size >= 1024 ** 4:
|
||||||
size /= 1073741824
|
size /= 1024 ** 4
|
||||||
units = 'Gb'
|
units = 'TB'
|
||||||
elif size >= 1048576:
|
elif size >= 1024 ** 3:
|
||||||
size /= 1048576
|
size /= 1024 ** 3
|
||||||
units = 'Mb'
|
units = 'GB'
|
||||||
elif size >= 1024:
|
elif size >= 1024 ** 2:
|
||||||
size /= 1024
|
size /= 1024 ** 2
|
||||||
units = 'Kb'
|
units = 'MB'
|
||||||
|
elif size >= 1024 ** 1:
|
||||||
|
size /= 1024 ** 1
|
||||||
|
units = 'KB'
|
||||||
else:
|
else:
|
||||||
units = ' b'
|
size /= 1024 ** 0
|
||||||
|
units = ' B'
|
||||||
|
|
||||||
# Return
|
# Return
|
||||||
return '{size:>{width}.{decimals}f} {units}'.format(
|
return '{size:>{width}.{decimals}f} {units}'.format(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue