Skip to content
Snippets Groups Projects
Commit 499ea7e5 authored by Aurélien Dunand's avatar Aurélien Dunand Committed by Seblu
Browse files

Add human_size function

parent 0526bb66
No related branches found
No related tags found
No related merge requests found
......@@ -148,3 +148,13 @@ def getsize(path):
if stat.S_ISDIR(filestat.st_mode) or stat.S_ISREG(filestat.st_mode):
total_sz += filestat.st_size
return total_sz
def human_size(num):
'''
Return human readable size
'''
for x in ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0
return "%3.1f%s" % (num, x)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment