fetcher'dan progress'i kaldır. progress göstermek ui'nin işi.
Burada bir-iki düzenleme daha gerekebilir...
This commit is contained in:
+2
-22
@@ -19,11 +19,6 @@ class FetchError (Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# helper functions
|
# helper functions
|
||||||
def displayProgress(pd):
|
|
||||||
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
|
||||||
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
|
||||||
ui.info(out)
|
|
||||||
|
|
||||||
def fetchUrl(url, dest, percentHook=None):
|
def fetchUrl(url, dest, percentHook=None):
|
||||||
fetch = Fetcher(url, dest)
|
fetch = Fetcher(url, dest)
|
||||||
fetch.percentHook = percentHook
|
fetch.percentHook = percentHook
|
||||||
@@ -66,7 +61,7 @@ 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 = Progress(totalsize)
|
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()
|
||||||
@@ -87,7 +82,7 @@ class Fetcher:
|
|||||||
oldsize, tt = size, time()
|
oldsize, tt = size, time()
|
||||||
if p.update(size):
|
if p.update(size):
|
||||||
self.percent = p.percent
|
self.percent = p.percent
|
||||||
if self.percentHook != None:
|
if self.percentHook:
|
||||||
retval = {'filename': self.url.filename(),
|
retval = {'filename': self.url.filename(),
|
||||||
'percent' : self.percent,
|
'percent' : self.percent,
|
||||||
'rate': self.rate,
|
'rate': self.rate,
|
||||||
@@ -141,18 +136,3 @@ class Fetcher:
|
|||||||
def err (self, error):
|
def err (self, error):
|
||||||
raise FetchError(error)
|
raise FetchError(error)
|
||||||
|
|
||||||
class Progress:
|
|
||||||
def __init__(self, totalsize):
|
|
||||||
self.totalsize = totalsize
|
|
||||||
self.percent = 0
|
|
||||||
|
|
||||||
def update(self, size):
|
|
||||||
if not self.totalsize:
|
|
||||||
return 100
|
|
||||||
|
|
||||||
percent = (size * 100) / self.totalsize
|
|
||||||
if percent and self.percent is not percent:
|
|
||||||
self.percent = percent
|
|
||||||
return percent
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|||||||
+2
-2
@@ -25,9 +25,9 @@ class Index(XmlFile):
|
|||||||
url = PUrl(filename)
|
url = PUrl(filename)
|
||||||
if url.isRemoteFile():
|
if url.isRemoteFile():
|
||||||
from os import getcwd
|
from os import getcwd
|
||||||
from fetcher import fetchUrl, displayProgress
|
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(), displayProgress)
|
fetchUrl(url, getcwd(), ui.displayProgress)
|
||||||
self.filename = url.filename()
|
self.filename = url.filename()
|
||||||
|
|
||||||
self.readxml(self.filename)
|
self.readxml(self.filename)
|
||||||
|
|||||||
+3
-2
@@ -16,10 +16,11 @@ class Package:
|
|||||||
|
|
||||||
if url.isRemoteFile():
|
if url.isRemoteFile():
|
||||||
from os import getcwd
|
from os import getcwd
|
||||||
from fetcher import fetchUrl, displayProgress
|
from fetcher import fetchUrl
|
||||||
|
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(), displayProgress)
|
fetchUrl(url, getcwd(), ui.displayProgress)
|
||||||
self.filename = url.filename()
|
self.filename = url.filename()
|
||||||
|
|
||||||
self.impl = archive.ArchiveZip(self.filename, 'zip', mode)
|
self.impl = archive.ArchiveZip(self.filename, 'zip', mode)
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,8 @@ from config import config
|
|||||||
from bsddb import db
|
from bsddb import db
|
||||||
|
|
||||||
class PackageDB(object):
|
class PackageDB(object):
|
||||||
|
"""PackageDB class provides an interface to the package database with
|
||||||
|
a delegated dbshelve object"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
util.check_dir(config.db_dir())
|
util.check_dir(config.db_dir())
|
||||||
filename = os.path.join(config.db_dir(), 'package.bdb')
|
filename = os.path.join(config.db_dir(), 'package.bdb')
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from archive import Archive
|
|||||||
from purl import PUrl
|
from purl import PUrl
|
||||||
from ui import ui
|
from ui import ui
|
||||||
from config import config
|
from config import config
|
||||||
from fetcher import fetchUrl, displayProgress
|
from fetcher import fetchUrl
|
||||||
import util
|
import util
|
||||||
|
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ class SourceArchive:
|
|||||||
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 = displayProgress
|
self.showProgress = ui.displayProgress
|
||||||
fetchUrl(self.url, config.archives_dir(), self.showProgress)
|
fetchUrl(self.url, config.archives_dir(), self.showProgress)
|
||||||
|
|
||||||
def isCached(self, interactive=True):
|
def isCached(self, interactive=True):
|
||||||
|
|||||||
+16
-16
@@ -14,13 +14,6 @@ class CLI:
|
|||||||
def __init__(self, debuggy = True):
|
def __init__(self, debuggy = True):
|
||||||
self.showDebug = debuggy
|
self.showDebug = debuggy
|
||||||
|
|
||||||
class Progress:
|
|
||||||
def __init__(self, name, symbol):
|
|
||||||
self.name = name
|
|
||||||
self.percent = 0
|
|
||||||
self.rate = 0
|
|
||||||
self.symbol = symbol
|
|
||||||
|
|
||||||
def info(self, msg):
|
def info(self, msg):
|
||||||
sys.stdout.write(colorize(msg, 'blue'))
|
sys.stdout.write(colorize(msg, 'blue'))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@@ -34,18 +27,25 @@ class CLI:
|
|||||||
sys.stdout.write(colorize(msg, 'red'))
|
sys.stdout.write(colorize(msg, 'red'))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def startProgress(self, name, symbol):
|
class Progress:
|
||||||
## support one progress for now
|
def __init__(self, totalsize):
|
||||||
self.activeProgress = Progress(name, symbol)
|
self.totalsize = totalsize
|
||||||
|
self.percent = 0
|
||||||
|
|
||||||
|
def update(self, size):
|
||||||
|
if not self.totalsize:
|
||||||
|
return 100
|
||||||
|
|
||||||
def updateProgress(self, percent, rate):
|
percent = (size * 100) / self.totalsize
|
||||||
self.activeProgress.percent = percent
|
if percent and self.percent is not percent:
|
||||||
self.activeProgress.rate = rate
|
self.percent = percent
|
||||||
self.displayProgress(pd)
|
return percent
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
def displayProgress(pd):
|
def displayProgress(self, pd):
|
||||||
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
||||||
(self.name, self.percent, self.rate, self.symbol)
|
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||||
self.info(out)
|
self.info(out)
|
||||||
|
|
||||||
# default UI is CLI
|
# default UI is CLI
|
||||||
|
|||||||
Reference in New Issue
Block a user