fetcher.py : fetcher'in geri dönüş değerleri bir dictionary haline geldi (böyle bir fonkisyon için çok daha mantıklı), semboller (KB/s, MB/s vs) eklendi, bir de artık hatasız dlrate hesaplıyor..
tests/fetch_file : fetcher'ın değişen dönüş değerine göre güncellendi. pisibuild.py : fetcher'ın değişen dönüş değerine göre güncellendi, += fixindentation(pisibuild.py).. pisi-build : pisi-build += fixindentation(pisi-build)
This commit is contained in:
+22
-11
@@ -27,8 +27,8 @@ class Fetcher:
|
|||||||
self.filepath = ""
|
self.filepath = ""
|
||||||
self.filename = ""
|
self.filename = ""
|
||||||
self.percent = 0
|
self.percent = 0
|
||||||
self.rate = 0
|
self.rate = 0.0
|
||||||
self.percentHook = None
|
self.percentHook = None
|
||||||
from string import split
|
from string import split
|
||||||
u = urlparse.urlparse(self.uri)
|
u = urlparse.urlparse(self.uri)
|
||||||
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
|
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
|
||||||
@@ -54,11 +54,13 @@ class Fetcher:
|
|||||||
return self.filedest + "/" + self.filename
|
return self.filedest + "/" + self.filename
|
||||||
|
|
||||||
def doGrab(self, file, dest, totalsize):
|
def doGrab(self, file, dest, totalsize):
|
||||||
from time import time
|
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
|
||||||
tnow, oldsize = int(time()), 0
|
from time import time
|
||||||
|
tt, oldsize = int(time()), 0
|
||||||
p = Progress(totalsize)
|
p = Progress(totalsize)
|
||||||
bs, size = 1024*4, 0
|
bs, size = 1024, 0
|
||||||
|
symbol, depth = "B/s", 0
|
||||||
|
st = time()
|
||||||
chunk = file.read(bs)
|
chunk = file.read(bs)
|
||||||
size = size + len(chunk)
|
size = size + len(chunk)
|
||||||
self.percent = p.update(size)
|
self.percent = p.update(size)
|
||||||
@@ -66,13 +68,22 @@ class Fetcher:
|
|||||||
dest.write(chunk)
|
dest.write(chunk)
|
||||||
chunk = file.read(bs)
|
chunk = file.read(bs)
|
||||||
size = size + len(chunk)
|
size = size + len(chunk)
|
||||||
if tnow != int(time()):
|
ct = time()
|
||||||
self.rate = (size - oldsize) / (int(time()) - tnow) / 1024
|
if int(tt) != int(ct):
|
||||||
oldsize, tnow = size, int(time())
|
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):
|
if p.update(size):
|
||||||
self.percent = p.percent
|
self.percent = p.percent
|
||||||
if self.percentHook != None:
|
if self.percentHook != None:
|
||||||
self.percentHook(self.filename, self.percent, self.rate)
|
retval = {'filename': self.filename,
|
||||||
|
'percent' : self.percent,
|
||||||
|
'rate': self.rate,
|
||||||
|
'symbol': symbol}
|
||||||
|
self.percentHook(retval)
|
||||||
|
|
||||||
dest.close()
|
dest.close()
|
||||||
print ""
|
print ""
|
||||||
|
|||||||
+12
-11
@@ -9,8 +9,9 @@ import util
|
|||||||
from pisibuild import PisiBuild, PisiBuildError
|
from pisibuild import PisiBuild, PisiBuildError
|
||||||
|
|
||||||
|
|
||||||
def doProgress(filename, percent, rate):
|
def doProgress(filename, percent, rate, symbol):
|
||||||
out = '\r%-30.30s %%%3d %d KB/s' % (filename, percent, rate)
|
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
||||||
|
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||||
util.information(out)
|
util.information(out)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -22,15 +23,15 @@ def main():
|
|||||||
|
|
||||||
# getopt magic
|
# getopt magic
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:],"h",["help"])
|
opts, args = getopt.getopt(sys.argv[1:],"h",["help"])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
help()
|
help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt == "-h":
|
if opt == "-h":
|
||||||
help()
|
help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# pspec(PISI Spec) to be used for package
|
# pspec(PISI Spec) to be used for package
|
||||||
pspec = ""
|
pspec = ""
|
||||||
@@ -39,10 +40,10 @@ def main():
|
|||||||
# but pisi-build may build many packages (pspecs given in order)
|
# but pisi-build may build many packages (pspecs given in order)
|
||||||
# sequentially.
|
# sequentially.
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
help()
|
help()
|
||||||
raise PisiBuildError, "pisi-build expects one (and only one) pspec file currently"
|
raise PisiBuildError, "pisi-build expects one (and only one) pspec file currently"
|
||||||
else:
|
else:
|
||||||
pspec = args[0]
|
pspec = args[0]
|
||||||
|
|
||||||
# doing the real job.
|
# doing the real job.
|
||||||
pb = PisiBuild(pspec)
|
pb = PisiBuild(pspec)
|
||||||
|
|||||||
+10
-10
@@ -18,19 +18,19 @@ class PisiBuildError(Exception):
|
|||||||
class PisiBuild:
|
class PisiBuild:
|
||||||
"""PisiBuild class, provides the package build and creation routines"""
|
"""PisiBuild class, provides the package build and creation routines"""
|
||||||
def __init__(self, pspecfile):
|
def __init__(self, pspecfile):
|
||||||
self.pspecfile = pspecfile
|
self.pspecfile = pspecfile
|
||||||
spec = SpecFile()
|
spec = SpecFile()
|
||||||
spec.read(pspecfile)
|
spec.read(pspecfile)
|
||||||
spec.verify() # check pspec integrity
|
spec.verify() # check pspec integrity
|
||||||
|
|
||||||
# additional processing on spec file
|
# additional processing on spec file
|
||||||
self.archiveName = basename(spec.archiveUri)
|
self.archiveName = basename(spec.archiveUri)
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
|
|
||||||
def fetchArchive(self, percentHook=None):
|
def fetchArchive(self, percentHook=None):
|
||||||
"""fetch an archive and store to pisiconfig.archives_dir
|
"""fetch an archive and store to pisiconfig.archives_dir
|
||||||
using fether.Fetcher"""
|
using fether.Fetcher"""
|
||||||
fetch = Fetcher(self.spec.archiveUri)
|
fetch = Fetcher(self.spec.archiveUri)
|
||||||
|
|
||||||
# check if source already cached
|
# check if source already cached
|
||||||
destpath = fetch.filedest + "/" + fetch.filename
|
destpath = fetch.filedest + "/" + fetch.filename
|
||||||
@@ -39,12 +39,12 @@ class PisiBuild:
|
|||||||
util.information(fetch.filename + " cached\n")
|
util.information(fetch.filename + " cached\n")
|
||||||
return
|
return
|
||||||
|
|
||||||
if percentHook:
|
if percentHook:
|
||||||
fetch.percentHook = percentHook
|
fetch.percentHook = percentHook
|
||||||
fetch.fetch()
|
fetch.fetch()
|
||||||
|
|
||||||
def unpackArchive(self):
|
def unpackArchive(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def applyPatches(self):
|
def applyPatches(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ sys.path.append("..")
|
|||||||
import fetcher
|
import fetcher
|
||||||
import pisiconfig
|
import pisiconfig
|
||||||
|
|
||||||
def doProgress(filename, percent, rate):
|
def doProgress(pd):
|
||||||
out = '\r%-30.30s %%%3d %d KB/s' % (filename, percent, rate)
|
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
||||||
|
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||||
stderr.write(out)
|
stderr.write(out)
|
||||||
stderr.flush()
|
stderr.flush()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user