From 5cad18b188cf51e31b9ae1ab5a1fd35eacf22d43 Mon Sep 17 00:00:00 2001 From: Shane Wang Date: Mon, 2 Apr 2012 16:29:17 +0800 Subject: Hob: unify _size_to_string() and _string_to_size() We call intsize_to_string (and string_to_intsize) in 3 different places. We unify the implementations into one place. (Bitbake rev: 578ce86a9ac2110f5b128aae582c6e0b3e739cec) Signed-off-by: Shane Wang Signed-off-by: Richard Purdie --- bitbake/lib/bb/ui/crumbs/hobpages.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'bitbake/lib/bb/ui/crumbs/hobpages.py') diff --git a/bitbake/lib/bb/ui/crumbs/hobpages.py b/bitbake/lib/bb/ui/crumbs/hobpages.py index d8e59c44dc..5045ea2019 100755 --- a/bitbake/lib/bb/ui/crumbs/hobpages.py +++ b/bitbake/lib/bb/ui/crumbs/hobpages.py @@ -83,3 +83,42 @@ class HobPage (gtk.VBox): tip_text = tip button = toolbar.append_item(buttonname, tip, None, icon, cb) return button + + @staticmethod + def _size_to_string(size): + try: + if not size: + size_str = "0 B" + else: + if len(str(int(size))) > 6: + size_str = '%.1f' % (size*1.0/(1024*1024)) + ' MB' + elif len(str(int(size))) > 3: + size_str = '%.1f' % (size*1.0/1024) + ' KB' + else: + size_str = str(size) + ' B' + except: + size_str = "0 B" + return size_str + + @staticmethod + def _string_to_size(str_size): + try: + if not str_size: + size = 0 + else: + unit = str_size.split() + if len(unit) > 1: + if unit[1] == 'MB': + size = float(unit[0])*1024*1024 + elif unit[1] == 'KB': + size = float(unit[0])*1024 + elif unit[1] == 'B': + size = float(unit[0]) + else: + size = 0 + else: + size = float(unit[0]) + except: + size = 0 + return size + -- cgit v1.2.3-54-g00ecf