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()