From 492cac2c4c390c3054b930e2cd04d84ab9365c9b Mon Sep 17 00:00:00 2001 From: "A. Murat Eren" Date: Fri, 17 Mar 2006 21:50:42 +0000 Subject: [PATCH] =?UTF-8?q?=20size=20ve=20rate=20i=C3=A7in=20kolay=20okunu?= =?UTF-8?q?r=20d=C3=B6n=C3=BC=C5=9F=C3=BCmleri=20util=20i=C3=A7erisinde=20?= =?UTF-8?q?iki=20fonksiyona=20ta=C5=9F=C4=B1yal=C4=B1m.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pisi/fetcher.py | 8 ++------ pisi/util.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pisi/fetcher.py b/pisi/fetcher.py index 43c4b2c4..4a86535a 100644 --- a/pisi/fetcher.py +++ b/pisi/fetcher.py @@ -95,12 +95,11 @@ class Fetcher: def _do_grab(self, fileURI, dest, total_size): ctx.ui.notify(pisi.ui.downloading, url = fileURI) - symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s'] bs, tt, = 1024, int(time()) s_time = time() Tdiff = lambda: time() - s_time downloaded_size = exist_size = self.exist_size - symbol, depth = 'B/s', 0 + symbol = 'B/s' st = time() chunk = fileURI.read(bs) downloaded_size += len(chunk) @@ -122,11 +121,8 @@ class Fetcher: self.eta = '%02d:%02d:%02d' %\ tuple([i for i in gmtime((Tdiff() * (100 - self.percent)) / self.percent)[3:6]]) - while self.rate > 1000 and depth < 3: - self.rate /= 1024 - depth += 1 + self.rate, symbol = util.human_readable_rate(self.rate) - symbol, depth = symbols[depth], 0 tt = time() if self.progress: diff --git a/pisi/util.py b/pisi/util.py index ec057abb..b5e786a1 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -121,6 +121,18 @@ def remove_prefix(a,b): assert prefix(a,b) return b[len(a):] +def human_readable_size(size = 0): + symbols, depth = [' B', 'KB', 'MB', 'GB'], 0 + + while size > 1000 and depth < 3: + size = float(size / 1024) + depth += 1 + + return size, symbols[depth] + +def human_readable_rate(size = 0): + x = human_readable_size(size) + return x[0], x[1] + '/s' ############################## # Process Releated Functions # @@ -644,3 +656,4 @@ def pure_package_name(package_name): def generate_pisi_file(patchFile, fromFile, toFile): run_batch("xdelta patch %s %s %s" % (patchFile, fromFile, toFile)) +