progress hadisesini biraz daha düzeltmeye çalıştım...
This commit is contained in:
@@ -76,13 +76,15 @@ class PisiCLI(object):
|
|||||||
#print 'rargs', parser.rargs, 'vals', parser.values
|
#print 'rargs', parser.rargs, 'vals', parser.values
|
||||||
self.command = parser.rargs[0]
|
self.command = parser.rargs[0]
|
||||||
|
|
||||||
# now for the real parser
|
# # now for the real parser
|
||||||
parser = OptionParser(usage=usage, version="%prog " + pisi.__version__)
|
# parser = OptionParser(usage=usage, version="%prog " + pisi.__version__)
|
||||||
parser.allow_interspersed_args = False
|
# parser.allow_interspersed_args = False
|
||||||
self.parser = commonopts(parser)
|
# self.parser = commonopts(parser)
|
||||||
self.add_subcommand_opts()
|
# self.add_subcommand_opts()
|
||||||
(self.options, args) = self.parser.parse_args()
|
# (self.options, args) = sel
|
||||||
|
# f.parser.parse_args()
|
||||||
self.args = args[1:]
|
self.args = args[1:]
|
||||||
|
print options
|
||||||
|
|
||||||
self.authInfo = None
|
self.authInfo = None
|
||||||
self.checkAuthInfo()
|
self.checkAuthInfo()
|
||||||
|
|||||||
+11
-9
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Yet another Pisi module for fetching files from various sources. Of
|
# Yet another Pisi module for fetching files from various sources. Of
|
||||||
@@ -19,11 +20,11 @@ class FetchError (Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# helper functions
|
# helper functions
|
||||||
def fetchUrl(url, dest, percentHook=None):
|
def fetchUrl(url, dest, progress=None):
|
||||||
fetch = Fetcher(url, dest)
|
fetch = Fetcher(url, dest)
|
||||||
fetch.percentHook = percentHook
|
fetch.progress = progress
|
||||||
fetch.fetch()
|
fetch.fetch()
|
||||||
if percentHook:
|
if progress:
|
||||||
ui.info('\n')
|
ui.info('\n')
|
||||||
|
|
||||||
|
|
||||||
@@ -61,13 +62,14 @@ class Fetcher:
|
|||||||
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
|
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
|
||||||
from time import time
|
from time import time
|
||||||
tt, oldsize = int(time()), 0
|
tt, oldsize = int(time()), 0
|
||||||
p = ui.Progress(totalsize)
|
|
||||||
bs, size = 1024, 0
|
bs, size = 1024, 0
|
||||||
symbol, depth = "B/s", 0
|
symbol, depth = "B/s", 0
|
||||||
st = time()
|
st = time()
|
||||||
chunk = fileURI.read(bs)
|
chunk = fileURI.read(bs)
|
||||||
size = size + len(chunk)
|
size = size + len(chunk)
|
||||||
self.percent = p.update(size)
|
if self.progress:
|
||||||
|
p = self.progress(totalsize)
|
||||||
|
self.percent = p.update(size)
|
||||||
while chunk:
|
while chunk:
|
||||||
dest.write(chunk)
|
dest.write(chunk)
|
||||||
chunk = fileURI.read(bs)
|
chunk = fileURI.read(bs)
|
||||||
@@ -80,14 +82,14 @@ class Fetcher:
|
|||||||
depth += 1
|
depth += 1
|
||||||
symbol, depth = symbols[depth], 0
|
symbol, depth = symbols[depth], 0
|
||||||
oldsize, tt = size, time()
|
oldsize, tt = size, time()
|
||||||
if p.update(size):
|
if self.progress:
|
||||||
self.percent = p.percent
|
if p.update(size):
|
||||||
if self.percentHook:
|
self.percent = p.percent
|
||||||
retval = {'filename': self.url.filename(),
|
retval = {'filename': self.url.filename(),
|
||||||
'percent' : self.percent,
|
'percent' : self.percent,
|
||||||
'rate': self.rate,
|
'rate': self.rate,
|
||||||
'symbol': symbol}
|
'symbol': symbol}
|
||||||
self.percentHook(retval)
|
ui.displayProgress(retval)
|
||||||
|
|
||||||
dest.close()
|
dest.close()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ class Index(XmlFile):
|
|||||||
from os import getcwd
|
from os import getcwd
|
||||||
from fetcher import fetchUrl
|
from fetcher import fetchUrl
|
||||||
# TODO: index dosyasını indirmek için bir yer bulmak lazım.
|
# 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.filename = url.filename()
|
||||||
|
|
||||||
self.readxml(self.filename)
|
self.readxml(self.filename)
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ class Package:
|
|||||||
from ui import ui
|
from ui import ui
|
||||||
# TODO: belki Constants.packages_dir() gibi bir yere
|
# TODO: belki Constants.packages_dir() gibi bir yere
|
||||||
# indirmek daha iyi olur.
|
# indirmek daha iyi olur.
|
||||||
fetchUrl(url, getcwd(), ui.displayProgress)
|
fetchUrl(url, getcwd(), ui.Progress)
|
||||||
self.filename = url.filename()
|
self.filename = url.filename()
|
||||||
|
|
||||||
self.impl = archive.ArchiveZip(self.filename, 'zip', mode)
|
self.impl = archive.ArchiveZip(self.filename, 'zip', mode)
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ class SourceArchive:
|
|||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.url = PUrl(self.ctx.spec.source.archiveUri)
|
self.url = PUrl(self.ctx.spec.source.archiveUri)
|
||||||
self.dest = join(config.archives_dir(), self.url.filename())
|
self.dest = join(config.archives_dir(), self.url.filename())
|
||||||
self.showProgress = None
|
|
||||||
|
|
||||||
def fetch(self, interactive=True):
|
def fetch(self, interactive=True):
|
||||||
if not self.isCached(interactive):
|
if not self.isCached(interactive):
|
||||||
if interactive:
|
if interactive:
|
||||||
self.showProgress = ui.displayProgress
|
progress = ui.Progress
|
||||||
fetchUrl(self.url, config.archives_dir(), self.showProgress)
|
else: progress = None
|
||||||
|
fetchUrl(self.url, config.archives_dir(), progress)
|
||||||
|
|
||||||
def isCached(self, interactive=True):
|
def isCached(self, interactive=True):
|
||||||
if not access(self.dest, R_OK):
|
if not access(self.dest, R_OK):
|
||||||
|
|||||||
+1
-1
@@ -31,7 +31,7 @@ class CLI:
|
|||||||
def __init__(self, totalsize):
|
def __init__(self, totalsize):
|
||||||
self.totalsize = totalsize
|
self.totalsize = totalsize
|
||||||
self.percent = 0
|
self.percent = 0
|
||||||
|
|
||||||
def update(self, size):
|
def update(self, size):
|
||||||
if not self.totalsize:
|
if not self.totalsize:
|
||||||
return 100
|
return 100
|
||||||
|
|||||||
Reference in New Issue
Block a user