Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/util.py
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-08-20 16:05:29 (GMT)
committer Tomeu Vizoso <tomeu@sugarlabs.org>2009-08-25 17:26:41 (GMT)
commit6c3fd0346c1876ad501c3c91d50cdf42f7e0a9dc (patch)
tree9bf80d2cf43646e5a7fd17c2d1f9bf6ffd8e2219 /src/sugar/util.py
parent9a650899782014338bdc20eaddbfd29749e9cdab (diff)
add sugar.util.format_size
Diffstat (limited to 'src/sugar/util.py')
-rw-r--r--src/sugar/util.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/sugar/util.py b/src/sugar/util.py
index 034038b..c35d366 100644
--- a/src/sugar/util.py
+++ b/src/sugar/util.py
@@ -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)