From 96a9f0e3a301f8889d4bb13675797227f501f89f Mon Sep 17 00:00:00 2001 From: "A. Murat Eren" Date: Sun, 12 Jun 2005 12:08:00 +0000 Subject: [PATCH] =?UTF-8?q?=20fetcher.py=20=20=20=20=20=20=20:=20fetcher'i?= =?UTF-8?q?n=20geri=20d=C3=B6n=C3=BC=C5=9F=20de=C4=9Ferleri=20bir=20dictio?= =?UTF-8?q?nary=20haline=20geldi=20(b=C3=B6yle=20bir=20fonkisyon=20i=C3=A7?= =?UTF-8?q?in=20=C3=A7ok=20daha=20mant=C4=B1kl=C4=B1),=20semboller=20(KB/s?= =?UTF-8?q?,=20MB/s=20vs)=20eklendi,=20bir=20de=20art=C4=B1k=20hatas=C4=B1?= =?UTF-8?q?z=20dlrate=20hesapl=C4=B1yor..=20=20tests/fetch=5Ffile=20:=20fe?= =?UTF-8?q?tcher'=C4=B1n=20de=C4=9Fi=C5=9Fen=20d=C3=B6n=C3=BC=C5=9F=20de?= =?UTF-8?q?=C4=9Ferine=20g=C3=B6re=20g=C3=BCncellendi.=20=20pisibuild.py?= =?UTF-8?q?=20=20=20=20=20:=20fetcher'=C4=B1n=20de=C4=9Fi=C5=9Fen=20d?= =?UTF-8?q?=C3=B6n=C3=BC=C5=9F=20de=C4=9Ferine=20g=C3=B6re=20g=C3=BCncelle?= =?UTF-8?q?ndi,=20+=3D=20fixindentation(pisibuild.py)..=20=20pisi-build=20?= =?UTF-8?q?=20=20=20=20=20=20:=20pisi-build=20+=3D=20fixindentation(pisi-b?= =?UTF-8?q?uild)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fetcher.py | 33 ++++++++++++++++++++++----------- src/pisi-build | 23 ++++++++++++----------- src/pisibuild.py | 20 ++++++++++---------- src/tests/fetch_file | 5 +++-- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/fetcher.py b/src/fetcher.py index 49e520cb..12d79ea2 100755 --- a/src/fetcher.py +++ b/src/fetcher.py @@ -27,8 +27,8 @@ class Fetcher: self.filepath = "" self.filename = "" self.percent = 0 - self.rate = 0 - self.percentHook = None + self.rate = 0.0 + self.percentHook = None from string import split u = urlparse.urlparse(self.uri) self.scheme, self.netloc, self.filepath = u[0], u[1], u[2] @@ -54,11 +54,13 @@ class Fetcher: return self.filedest + "/" + self.filename def doGrab(self, file, dest, totalsize): - from time import time - tnow, oldsize = int(time()), 0 + symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s'] + from time import time + tt, oldsize = int(time()), 0 p = Progress(totalsize) - bs, size = 1024*4, 0 - + bs, size = 1024, 0 + symbol, depth = "B/s", 0 + st = time() chunk = file.read(bs) size = size + len(chunk) self.percent = p.update(size) @@ -66,13 +68,22 @@ class Fetcher: dest.write(chunk) chunk = file.read(bs) size = size + len(chunk) - if tnow != int(time()): - self.rate = (size - oldsize) / (int(time()) - tnow) / 1024 - oldsize, tnow = size, int(time()) + ct = time() + if int(tt) != int(ct): + self.rate = size / (ct - st) + while self.rate > 1000 and depth < 3: + self.rate /= 1024 + depth += 1 + symbol, depth = symbols[depth], 0 + oldsize, tt = size, time() if p.update(size): self.percent = p.percent - if self.percentHook != None: - self.percentHook(self.filename, self.percent, self.rate) + if self.percentHook != None: + retval = {'filename': self.filename, + 'percent' : self.percent, + 'rate': self.rate, + 'symbol': symbol} + self.percentHook(retval) dest.close() print "" diff --git a/src/pisi-build b/src/pisi-build index 90755667..de3fbd96 100755 --- a/src/pisi-build +++ b/src/pisi-build @@ -9,8 +9,9 @@ import util from pisibuild import PisiBuild, PisiBuildError -def doProgress(filename, percent, rate): - out = '\r%-30.30s %%%3d %d KB/s' % (filename, percent, rate) +def doProgress(filename, percent, rate, symbol): + out = '\r%-30.30s %3d%% %12.2f %s' % \ + (pd['filename'], pd['percent'], pd['rate'], pd['symbol']) util.information(out) def main(): @@ -22,15 +23,15 @@ def main(): # getopt magic try: - opts, args = getopt.getopt(sys.argv[1:],"h",["help"]) + opts, args = getopt.getopt(sys.argv[1:],"h",["help"]) except getopt.GetoptError: - help() - sys.exit(1) + help() + sys.exit(1) for opt, arg in opts: - if opt == "-h": - help() - sys.exit(1) + if opt == "-h": + help() + sys.exit(1) # pspec(PISI Spec) to be used for package pspec = "" @@ -39,10 +40,10 @@ def main(): # but pisi-build may build many packages (pspecs given in order) # sequentially. if len(args) != 1: - help() - raise PisiBuildError, "pisi-build expects one (and only one) pspec file currently" + help() + raise PisiBuildError, "pisi-build expects one (and only one) pspec file currently" else: - pspec = args[0] + pspec = args[0] # doing the real job. pb = PisiBuild(pspec) diff --git a/src/pisibuild.py b/src/pisibuild.py index 93659886..b84d686d 100644 --- a/src/pisibuild.py +++ b/src/pisibuild.py @@ -18,19 +18,19 @@ class PisiBuildError(Exception): class PisiBuild: """PisiBuild class, provides the package build and creation routines""" def __init__(self, pspecfile): - self.pspecfile = pspecfile - spec = SpecFile() + self.pspecfile = pspecfile + spec = SpecFile() spec.read(pspecfile) spec.verify() # check pspec integrity # additional processing on spec file - self.archiveName = basename(spec.archiveUri) + self.archiveName = basename(spec.archiveUri) self.spec = spec def fetchArchive(self, percentHook=None): - """fetch an archive and store to pisiconfig.archives_dir - using fether.Fetcher""" - fetch = Fetcher(self.spec.archiveUri) + """fetch an archive and store to pisiconfig.archives_dir + using fether.Fetcher""" + fetch = Fetcher(self.spec.archiveUri) # check if source already cached destpath = fetch.filedest + "/" + fetch.filename @@ -39,12 +39,12 @@ class PisiBuild: util.information(fetch.filename + " cached\n") return - if percentHook: - fetch.percentHook = percentHook - fetch.fetch() + if percentHook: + fetch.percentHook = percentHook + fetch.fetch() def unpackArchive(self): - pass + pass def applyPatches(self): pass diff --git a/src/tests/fetch_file b/src/tests/fetch_file index d36947c5..19daa135 100755 --- a/src/tests/fetch_file +++ b/src/tests/fetch_file @@ -13,8 +13,9 @@ sys.path.append("..") import fetcher import pisiconfig -def doProgress(filename, percent, rate): - out = '\r%-30.30s %%%3d %d KB/s' % (filename, percent, rate) +def doProgress(pd): + out = '\r%-30.30s %3d%% %12.2f %s' % \ + (pd['filename'], pd['percent'], pd['rate'], pd['symbol']) stderr.write(out) stderr.flush()