add sugar.util.format_size
This commit is contained in:
parent
9a65089978
commit
6c3fd0346c
@ -303,3 +303,15 @@ def _cleanup_temp_files():
|
||||
|
||||
atexit.register(_cleanup_temp_files)
|
||||
|
||||
|
||||
def format_size(size):
|
||||
if not size:
|
||||
return _('Empty')
|
||||
elif size < 1024:
|
||||
return _('%d B') % size
|
||||
elif size < 1024**2:
|
||||
return _('%d KB') % (size / 1024)
|
||||
elif size < 1024**3:
|
||||
return _('%d MB') % (size / 1024**2)
|
||||
else:
|
||||
return _('%d GB') % (size / 1024**3)
|
||||
|
Loading…
Reference in New Issue
Block a user