Kaydet (Commit) db6a4ac4 authored tarafından Barış Metin's avatar Barış Metin

progress hadisesini biraz daha düzeltmeye çalıştım...

üst e54fe0dd
......@@ -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()
......
# -*- 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()
......
......@@ -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)
......
......@@ -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)
......
......@@ -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):
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment