Ticket #1215: 0001-add-sugar.util.format_size.patch

File 0001-add-sugar.util.format_size.patch, 844 bytes (added by sascha_silbe, 13 years ago)

add sugar.util.format_size()

  • src/sugar/util.py

    From 9c9e6fbc1f33854b07bd544eb983359abb04c442 Mon Sep 17 00:00:00 2001
    From: Sascha Silbe <sascha@silbe.org>
    Date: Thu, 20 Aug 2009 18:05:29 +0200
    Subject: [PATCH] add sugar.util.format_size
    
    ---
     src/sugar/util.py |   12 ++++++++++++
     1 files changed, 12 insertions(+), 0 deletions(-)
    
    diff --git a/src/sugar/util.py b/src/sugar/util.py
    index 034038b..c35d366 100644
    a b def _cleanup_temp_files(): 
    303303
    304304atexit.register(_cleanup_temp_files)
    305305
     306
     307def format_size(size):
     308    if not size:
     309        return _('Empty')
     310    elif size < 1024:
     311        return _('%d B') % size
     312    elif size < 1024**2:
     313        return _('%d KB') % (size / 1024)
     314    elif size < 1024**3:
     315        return _('%d MB') % (size / 1024**2)
     316    else:
     317        return _('%d GB') % (size / 1024**3)