Commits

mickael9 committed 82459e2

Shortened humanize() (thanks @Zopieux !)

Comments (0)

Files changed (1)

 user.refresh()
 
 def humanize(nbytes):
-    if nbytes >= 10**9:
-        return '%.2f GB' % (nbytes / 10**9)
-    if nbytes >= 10**6:
-        return '%.2f MB' % (nbytes / 10**6)
-    if nbytes >= 10**3:
-        return '%.2f KB' % (nbytes / 10**3)
-
-    return '%.2f B' % nbytes
+    for (exp, unit) in ((9, 'GB'), (6, 'MB'), (3, 'KB'), (0, 'B')):
+       if nbytes >= 10**exp:
+           return '%.2f %s' % (nbytes / 10**exp, unit)
 
 print('Storage used : %s out of %s (%d %%)' % (
         humanize(user.storage_used),