diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2006-10-27 09:57:49 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2006-10-27 09:57:49 +0200 |
| commit | bed5736c7cf31070540bd7e27ffb073db3d7c396 (patch) | |
| tree | c733204d23625109cd282afcf2ac54539d300fd9 /UpdateManager/Common/utils.py | |
| parent | 590c710c9feef18c9a23676aab1ce0fb7b6d2f75 (diff) | |
| parent | dcee921a1107db6e5c8042598641b422a77e24c2 (diff) | |
| download | python-apt-bed5736c7cf31070540bd7e27ffb073db3d7c396.tar.gz | |
* merged from main
Diffstat (limited to 'UpdateManager/Common/utils.py')
| -rw-r--r-- | UpdateManager/Common/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/UpdateManager/Common/utils.py b/UpdateManager/Common/utils.py index 099cbfed..1fcd022f 100644 --- a/UpdateManager/Common/utils.py +++ b/UpdateManager/Common/utils.py @@ -1,4 +1,6 @@ import gtk +from gettext import gettext as _ +import locale def str_to_bool(str): if str == "0" or str.upper() == "FALSE": @@ -21,3 +23,20 @@ def error(parent, summary, message): res = d.run() d.destroy() return + +def humanize_size(bytes): + """ + Convert a given size in bytes to a nicer better readable unit + """ + if bytes == 0: + # TRANSLATORS: download size is 0 + return _("None") + elif bytes < 1024: + # TRANSLATORS: download size of very small updates + return _("1 KB") + elif bytes < 1024 * 1024: + # TRANSLATORS: download size of small updates, e.g. "250 KB" + return locale.format(_("%.0f KB"), bytes/1024) + else: + # TRANSLATORS: download size of updates, e.g. "2.3 MB" + return locale.format(_("%.1f MB"), bytes / 1024 / 1024) |
