Kaydet (Commit) 983199b7 authored tarafından Ali Rıza Keskin's avatar Ali Rıza Keskin

Burdan Süloya selam olsun: Progressbar renklendirmesi ekledim.

üst 52d0c000
......@@ -74,8 +74,16 @@ opttostr = {INSTALL: "install", REMOVE: "remove", REINSTALL: "reinstall", UPGRAD
class Install(AtomicOperation):
"""Install class, provides install routines for inary packages"""
def __init__(self, package_fname, ignore_dep=None, ignore_file_conflicts=None):
if not ctx.filesdb: ctx.filesdb = inary.db.filesdb.FilesDB()
def __init__(self, package_fname, ignore_dep=None, ignore_file_conflicts=None,installdb=None,filesdb=None):
if installdb == None:
self.installdb = inary.db.installdb.InstallDB()
else:
self.installdb = installdb
if filesdb == None:
self.filesdb = inary.db.filesdb.FilesDB()
else:
self.filesdb = filesdb
if not ctx.filesdb: ctx.filesdb = self.filesdb
"initialize from a file name"
super(Install, self).__init__(ignore_dep)
if not ignore_file_conflicts:
......@@ -91,16 +99,18 @@ class Install(AtomicOperation):
self.files = self.package.files
self.pkginfo = self.metadata.package
self.installedSize = self.metadata.package.installedSize
self.installdb = inary.db.installdb.InstallDB()
self.operation = INSTALL
self.store_old_paths = None
@staticmethod
def from_name(name,ignore_dep=None,packagedb=None,installdb=None):
def from_name(name,ignore_dep=None,packagedb=None,installdb=None,filesdb=None):
if packagedb == None:
packagedb = inary.db.packagedb.PackageDB()
if installdb == None:
installdb = inary.db.installdb.InstallDB()
if filesdb == None:
filesdb = inary.db.filesdb.FilesDB()
# download package and return an installer object
# find package in repository
repo = packagedb.which_repo(name)
......@@ -141,9 +151,7 @@ class Install(AtomicOperation):
if cached_file and util.sha1_file(cached_file) != pkg_hash:
os.unlink(cached_file)
cached_file = None
install_op = Install(pkg_path, ignore_dep)
install_op = Install(pkg_path, ignore_dep,installdb,filesdb)
# Bug 4113
if not cached_file:
downloaded_file = install_op.package.filepath
......
......@@ -178,13 +178,13 @@ class CLI(inary.ui.UI):
elif ka['operation'] == "fetching":
totalsize = '%.1f %s' % util.human_readable_size(ka['total_size'])
out = '\r%-30.50s (%s) %3d%% %9.2f %s [%s]' % \
out = '%-30.50s(%s)%3d%% %9.2f %s[%s]' % \
(ka['filename'], totalsize, ka['percent'],
ka['rate'], ka['symbol'], ka['eta'])
self.output(out)
self.output('\r\033[2K'+util.colorize_percent(out,ka['percent']))
util.xterm_title("%s (%d%%)" % (ka['filename'], ka['percent']))
else:
self.output("\r%s (%d%%)" % (ka['info'], ka['percent']))
self.output("\r\033[2K"+colorize_percent("%s (%d%%)" % (ka['info'], ka['percent']),ka['percent']))
util.xterm_title("%s (%d%%)" % (ka['info'], ka['percent']))
def status(self, msg=None, push_screen=True):
......
......@@ -157,6 +157,14 @@ class Constants(metaclass=Singleton):
'brightmagenta': "\033[01;35m",
'brightcyan': "\033[01;36m",
'brightwhite': "\033[01;37m",
'backgroundblack': "\033[01;40m",
'backgroundred': "\033[01;41m",
'backgroundgreen': "\033[01;42m",
'backgroundyellow': "\033[01;43m",
'backgroundblue': "\033[01;44m",
'backgroundmagenta': "\033[01;45m",
'backgroundcyan': "\033[01;46m",
'backgroundwhite': "\033[01;47m",
'faintblack': "\033[02;30m",
'faintred': "\033[02;31m",
'faintgreen': "\033[02;32m",
......
......@@ -141,7 +141,7 @@ class Fetcher:
self.destdir = destdir
self.destfile = destfile
self.progress = None
self.c = pycurl.Curl()
self.archive_file = os.path.join(destdir, destfile or url.filename())
self.partial_file = os.path.join(self.destdir, self.url.filename()) + ctx.const.partial_suffix
......@@ -164,44 +164,43 @@ class Fetcher:
raise FetchError(_('Access denied to destination file: "%s"') % self.archive_file)
else:
c = pycurl.Curl()
c.protocol = self.url.scheme()
c.setopt(c.URL, self.url.get_uri())
self.c.protocol = self.url.scheme()
self.c.setopt(self.c.URL, self.url.get_uri())
# Some runtime settings (user agent, bandwidth limit, timeout, redirections etc.)
c.setopt(pycurl.MAX_RECV_SPEED_LARGE, self._get_bandwith_limit())
c.setopt(pycurl.USERAGENT, ('Inary Fetcher/' + inary.__version__).encode("utf-8"))
c.setopt(pycurl.AUTOREFERER, 1)
c.setopt(pycurl.CONNECTTIMEOUT, timeout) # This for waiting to establish connection
# c.setopt(pycurl.TIMEOUT, timeout) # This for waiting to read data
c.setopt(pycurl.MAXREDIRS, 10)
c.setopt(pycurl.NOSIGNAL, True)
self.c.setopt(pycurl.MAX_RECV_SPEED_LARGE, self._get_bandwith_limit())
self.c.setopt(pycurl.USERAGENT, ('Inary Fetcher/' + inary.__version__).encode("utf-8"))
self.c.setopt(pycurl.AUTOREFERER, 1)
self.c.setopt(pycurl.CONNECTTIMEOUT, timeout) # This for waiting to establish connection
# self.c.setopt(pycurl.TIMEOUT, timeout) # This for waiting to read data
self.c.setopt(pycurl.MAXREDIRS, 10)
self.c.setopt(pycurl.NOSIGNAL, True)
# Header
# c.setopt(pycurl.HTTPHEADER, ["%s: %s" % header for header in self._get_http_headers().items()])
# self.c.setopt(pycurl.HTTPHEADER, ["%s: %s" % header for header in self._get_http_headers().items()])
handler = UIHandler()
handler.start(self.archive_file, self.url.get_uri(), self.url.filename())
if os.path.exists(self.partial_file):
file_id = open(self.partial_file, "ab")
c.setopt(c.RESUME_FROM, os.path.getsize(self.partial_file))
self.c.setopt(self.c.RESUME_FROM, os.path.getsize(self.partial_file))
ctx.ui.info(_("Download resuming..."))
else:
file_id = open(self.partial_file, "wb")
# Function sets
c.setopt(pycurl.DEBUGFUNCTION, ctx.ui.debug)
c.setopt(c.NOPROGRESS, False)
c.setopt(c.XFERINFOFUNCTION, handler.update)
self.c.setopt(pycurl.DEBUGFUNCTION, ctx.ui.debug)
self.c.setopt(self.c.NOPROGRESS, False)
self.c.setopt(self.c.XFERINFOFUNCTION, handler.update)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(c.WRITEDATA, file_id)
self.c.setopt(pycurl.FOLLOWLOCATION, 1)
self.c.setopt(self.c.WRITEDATA, file_id)
try:
c.perform()
self.c.perform()
file_id.close()
ctx.ui.info("\n")
ctx.ui.debug(_("Downloaded from:" + str(c.getinfo(c.EFFECTIVE_URL))))
c.close()
ctx.ui.debug(_("Downloaded from:" + str(self.c.getinfo(self.c.EFFECTIVE_URL))))
self.c.close()
except pycurl.error as x:
raise FetchError("Pycurl.Error: {}".format(x))
......
......@@ -36,6 +36,7 @@ def install_pkg_names(A, reinstall=False, extra=False):
installdb = inary.db.installdb.InstallDB()
packagedb = inary.db.packagedb.PackageDB()
filesdb = inary.db.filesdb.FilesDB()
A = [str(x) for x in A] # FIXME: why do we still get unicode input here? :/
# A was a list, remove duplicates
......@@ -96,7 +97,7 @@ def install_pkg_names(A, reinstall=False, extra=False):
extra_paths = {}
for x in order:
ctx.ui.info(_("Downloading %d / %d") % (order.index(x) + 1, len(order)), color="yellow")
install_op = atomicoperations.Install.from_name(x,ignore_dep,packagedb,installdb)
install_op = atomicoperations.Install.from_name(x,ignore_dep,packagedb,installdb,filesdb)
paths.append(install_op.package_fname)
if x in extra_packages or (extra and x in A):
extra_paths[install_op.package_fname] = x
......
......@@ -109,7 +109,7 @@ class Package:
url))
raise
else:
ctx.ui.info(_('{} [cached]').format(url.filename()),noln=True)
ctx.ui.info(util.colorize(_('{} [cached]').format(url.filename()),'backgroundblue'))
def add_to_package(self, fn, an=None):
"""Add a file or directory to package"""
......
......@@ -1048,6 +1048,13 @@ def colorize(msg, color):
else:
return str(msg)
def colorize_percent(msg,percent,color='backgroundgreen',color2='backgroundyellow'):
if len(msg)<1:
return str(msg)
lmsg=int((len(msg)*percent)/100)+1
if lmsg>=len(msg):
return str(ctx.const.colors[color] + msg + ctx.const.colors['default'])
return str(ctx.const.colors[color]+ msg[:lmsg]+ctx.const.colors[color2]+msg[lmsg:]+ctx.const.colors['default'])
def config_changed(config_file):
fpath = join_path(ctx.config.dest_dir(), config_file.path)
......
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