From 6c3fd0346c1876ad501c3c91d50cdf42f7e0a9dc Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Thu, 20 Aug 2009 18:05:29 +0200 Subject: [PATCH] add sugar.util.format_size --- src/sugar/util.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sugar/util.py b/src/sugar/util.py index 034038bb..c35d3664 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)