size ve rate için kolay okunur dönüşümleri util içerisinde iki fonksiyona taşıyalım.

This commit is contained in:
A. Murat Eren
2006-03-17 21:50:42 +00:00
parent 4e8c53300f
commit 492cac2c4c
2 changed files with 15 additions and 6 deletions
+2 -6
View File
@@ -95,12 +95,11 @@ class Fetcher:
def _do_grab(self, fileURI, dest, total_size): def _do_grab(self, fileURI, dest, total_size):
ctx.ui.notify(pisi.ui.downloading, url = fileURI) ctx.ui.notify(pisi.ui.downloading, url = fileURI)
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
bs, tt, = 1024, int(time()) bs, tt, = 1024, int(time())
s_time = time() s_time = time()
Tdiff = lambda: time() - s_time Tdiff = lambda: time() - s_time
downloaded_size = exist_size = self.exist_size downloaded_size = exist_size = self.exist_size
symbol, depth = 'B/s', 0 symbol = 'B/s'
st = time() st = time()
chunk = fileURI.read(bs) chunk = fileURI.read(bs)
downloaded_size += len(chunk) downloaded_size += len(chunk)
@@ -122,11 +121,8 @@ class Fetcher:
self.eta = '%02d:%02d:%02d' %\ self.eta = '%02d:%02d:%02d' %\
tuple([i for i in gmtime((Tdiff() * (100 - self.percent)) / self.percent)[3:6]]) tuple([i for i in gmtime((Tdiff() * (100 - self.percent)) / self.percent)[3:6]])
while self.rate > 1000 and depth < 3: self.rate, symbol = util.human_readable_rate(self.rate)
self.rate /= 1024
depth += 1
symbol, depth = symbols[depth], 0
tt = time() tt = time()
if self.progress: if self.progress:
+13
View File
@@ -121,6 +121,18 @@ def remove_prefix(a,b):
assert prefix(a,b) assert prefix(a,b)
return b[len(a):] 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 # # Process Releated Functions #
@@ -644,3 +656,4 @@ def pure_package_name(package_name):
def generate_pisi_file(patchFile, fromFile, toFile): def generate_pisi_file(patchFile, fromFile, toFile):
run_batch("xdelta patch %s %s %s" % (patchFile, fromFile, toFile)) run_batch("xdelta patch %s %s %s" % (patchFile, fromFile, toFile))