diff options
author | Shane Wang <shane.wang@intel.com> | 2012-04-02 16:29:17 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-04-05 18:48:07 +0100 |
commit | 5cad18b188cf51e31b9ae1ab5a1fd35eacf22d43 (patch) | |
tree | 11a8eb051bc869d455fc78bd11c51726f65d2f54 /bitbake/lib/bb/ui/crumbs/hobpages.py | |
parent | b9accbb42a40e1ace0f9790a20712b821bb2b3f6 (diff) | |
download | poky-5cad18b188cf51e31b9ae1ab5a1fd35eacf22d43.tar.gz |
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 <shane.wang@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/hobpages.py')
-rwxr-xr-x | bitbake/lib/bb/ui/crumbs/hobpages.py | 39 |
1 files changed, 39 insertions, 0 deletions
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): | |||
83 | tip_text = tip | 83 | tip_text = tip |
84 | button = toolbar.append_item(buttonname, tip, None, icon, cb) | 84 | button = toolbar.append_item(buttonname, tip, None, icon, cb) |
85 | return button | 85 | return button |
86 | |||
87 | @staticmethod | ||
88 | def _size_to_string(size): | ||
89 | try: | ||
90 | if not size: | ||
91 | size_str = "0 B" | ||
92 | else: | ||
93 | if len(str(int(size))) > 6: | ||
94 | size_str = '%.1f' % (size*1.0/(1024*1024)) + ' MB' | ||
95 | elif len(str(int(size))) > 3: | ||
96 | size_str = '%.1f' % (size*1.0/1024) + ' KB' | ||
97 | else: | ||
98 | size_str = str(size) + ' B' | ||
99 | except: | ||
100 | size_str = "0 B" | ||
101 | return size_str | ||
102 | |||
103 | @staticmethod | ||
104 | def _string_to_size(str_size): | ||
105 | try: | ||
106 | if not str_size: | ||
107 | size = 0 | ||
108 | else: | ||
109 | unit = str_size.split() | ||
110 | if len(unit) > 1: | ||
111 | if unit[1] == 'MB': | ||
112 | size = float(unit[0])*1024*1024 | ||
113 | elif unit[1] == 'KB': | ||
114 | size = float(unit[0])*1024 | ||
115 | elif unit[1] == 'B': | ||
116 | size = float(unit[0]) | ||
117 | else: | ||
118 | size = 0 | ||
119 | else: | ||
120 | size = float(unit[0]) | ||
121 | except: | ||
122 | size = 0 | ||
123 | return size | ||
124 | |||