diff --git a/pisi-cli b/pisi-cli index b14bea36..ae374f9d 100755 --- a/pisi-cli +++ b/pisi-cli @@ -76,13 +76,15 @@ class PisiCLI(object): #print 'rargs', parser.rargs, 'vals', parser.values self.command = parser.rargs[0] - # now for the real parser - parser = OptionParser(usage=usage, version="%prog " + pisi.__version__) - parser.allow_interspersed_args = False - self.parser = commonopts(parser) - self.add_subcommand_opts() - (self.options, args) = self.parser.parse_args() +# # now for the real parser +# parser = OptionParser(usage=usage, version="%prog " + pisi.__version__) +# parser.allow_interspersed_args = False +# self.parser = commonopts(parser) +# self.add_subcommand_opts() +# (self.options, args) = sel +# f.parser.parse_args() self.args = args[1:] + print options self.authInfo = None self.checkAuthInfo() diff --git a/pisi/fetcher.py b/pisi/fetcher.py index d253bb02..216dbf34 100644 --- a/pisi/fetcher.py +++ b/pisi/fetcher.py @@ -1,3 +1,4 @@ + # -*- coding: utf-8 -*- # Yet another Pisi module for fetching files from various sources. Of @@ -19,11 +20,11 @@ class FetchError (Exception): pass # helper functions -def fetchUrl(url, dest, percentHook=None): +def fetchUrl(url, dest, progress=None): fetch = Fetcher(url, dest) - fetch.percentHook = percentHook + fetch.progress = progress fetch.fetch() - if percentHook: + if progress: ui.info('\n') @@ -61,13 +62,14 @@ class Fetcher: symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s'] from time import time tt, oldsize = int(time()), 0 - p = ui.Progress(totalsize) bs, size = 1024, 0 symbol, depth = "B/s", 0 st = time() chunk = fileURI.read(bs) size = size + len(chunk) - self.percent = p.update(size) + if self.progress: + p = self.progress(totalsize) + self.percent = p.update(size) while chunk: dest.write(chunk) chunk = fileURI.read(bs) @@ -80,14 +82,14 @@ class Fetcher: depth += 1 symbol, depth = symbols[depth], 0 oldsize, tt = size, time() - if p.update(size): - self.percent = p.percent - if self.percentHook: + if self.progress: + if p.update(size): + self.percent = p.percent retval = {'filename': self.url.filename(), 'percent' : self.percent, 'rate': self.rate, 'symbol': symbol} - self.percentHook(retval) + ui.displayProgress(retval) dest.close() diff --git a/pisi/index.py b/pisi/index.py index 383ee618..5b3a635f 100644 --- a/pisi/index.py +++ b/pisi/index.py @@ -27,7 +27,7 @@ class Index(XmlFile): from os import getcwd from fetcher import fetchUrl # TODO: index dosyasını indirmek için bir yer bulmak lazım. - fetchUrl(url, getcwd(), ui.displayProgress) + fetchUrl(url, getcwd(), ui.Progress) self.filename = url.filename() self.readxml(self.filename) diff --git a/pisi/package.py b/pisi/package.py index e8f70836..11088f53 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -20,7 +20,7 @@ class Package: from ui import ui # TODO: belki Constants.packages_dir() gibi bir yere # indirmek daha iyi olur. - fetchUrl(url, getcwd(), ui.displayProgress) + fetchUrl(url, getcwd(), ui.Progress) self.filename = url.filename() self.impl = archive.ArchiveZip(self.filename, 'zip', mode) diff --git a/pisi/sourcearchive.py b/pisi/sourcearchive.py index f482efd3..da96ad63 100644 --- a/pisi/sourcearchive.py +++ b/pisi/sourcearchive.py @@ -26,13 +26,13 @@ class SourceArchive: self.ctx = ctx self.url = PUrl(self.ctx.spec.source.archiveUri) self.dest = join(config.archives_dir(), self.url.filename()) - self.showProgress = None def fetch(self, interactive=True): if not self.isCached(interactive): if interactive: - self.showProgress = ui.displayProgress - fetchUrl(self.url, config.archives_dir(), self.showProgress) + progress = ui.Progress + else: progress = None + fetchUrl(self.url, config.archives_dir(), progress) def isCached(self, interactive=True): if not access(self.dest, R_OK): diff --git a/pisi/ui.py b/pisi/ui.py index 6277b0cb..19933f61 100644 --- a/pisi/ui.py +++ b/pisi/ui.py @@ -31,7 +31,7 @@ class CLI: def __init__(self, totalsize): self.totalsize = totalsize self.percent = 0 - + def update(self, size): if not self.totalsize: return 100