diff options
Diffstat (limited to 'src/fringlib/fringutil.py')
-rw-r--r-- | src/fringlib/fringutil.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/fringlib/fringutil.py b/src/fringlib/fringutil.py index e174d66..4bfa5d7 100644 --- a/src/fringlib/fringutil.py +++ b/src/fringlib/fringutil.py @@ -10,3 +10,15 @@ def pretty_size(size): return "%u B" % size +def format_disk_space(size): + """ Convert bytes to a human readable format. + Returns a tuple, for example (20,"MiB") """ + + if size >= 1024*1024*1024: + return ("%.1f"%round(size/1024/1024/1024.0),"GiB") + elif size >= 1024*1024: + return ("%.1f"%round(size/1024/1024.0),"MiB") + elif size >= 1024: + return ("%.1f"%round(size/1024.0),"KiB") + else: + return ("%u"%size,"B") |