From 44ce5c5af96bb45d95c384f18f45c372f1ef75da Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 May 2010 11:25:08 -0600 Subject: [PATCH] Fix human readable size display to handle exabytes --- src/calibre/gui2/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 5bdaeb408e..40eec6a762 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -232,12 +232,10 @@ def info_dialog(parent, title, msg, det_msg='', show=False): def human_readable(size): """ Convert a size in bytes into a human readable form """ divisor, suffix = 1, "B" - if size < 1024*1024: - divisor, suffix = 1024., "KB" - elif size < 1024*1024*1024: - divisor, suffix = 1024*1024, "MB" - elif size < 1024*1024*1024*1024: - divisor, suffix = 1024*1024*1024, "GB" + for i, candidate in enumerate(('KB', 'MB', 'GB', 'TB', 'PB', 'EB')): + if size < 1024**(i+2): + divisor, suffix = 1024**(i+1), candidate + break size = str(float(size)/divisor) if size.find(".") > -1: size = size[:size.find(".")+2]