euscan: fixed progressbar
added -p option, now the progressbar is "global" and shows the total progress Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
@ -19,7 +19,8 @@ CONFIG = {
|
||||
'skip-robots-txt': False,
|
||||
'cache': False,
|
||||
'format': None,
|
||||
'indent': 2
|
||||
'indent': 2,
|
||||
'progress': False
|
||||
}
|
||||
|
||||
BLACKLIST_VERSIONS = [
|
||||
|
@ -11,15 +11,20 @@ from portage.output import EOutput, TermProgressBar
|
||||
|
||||
|
||||
class ProgressHandler(object):
|
||||
def __init__(self):
|
||||
def __init__(self, progress_bar):
|
||||
self.curval = 0
|
||||
self.maxval = 0
|
||||
self.last_update = 0
|
||||
self.min_display_latency = 0.2
|
||||
self.progress_bar = progress_bar
|
||||
|
||||
def on_progress(self, maxval=None, increment=1, label=None):
|
||||
self.maxval = maxval or self.maxval
|
||||
self.curval += increment
|
||||
|
||||
if label:
|
||||
self.progress_bar.label(label)
|
||||
|
||||
def on_progress(self, maxval, curval):
|
||||
self.maxval = maxval
|
||||
self.curval = curval
|
||||
cur_time = time.time()
|
||||
if cur_time - self.last_update >= self.min_display_latency:
|
||||
self.last_update = cur_time
|
||||
@ -33,7 +38,7 @@ def progress_bar():
|
||||
on_progress = None
|
||||
progress_bar = TermProgressBar()
|
||||
|
||||
progress_handler = ProgressHandler()
|
||||
progress_handler = ProgressHandler(progress_bar)
|
||||
on_progress = progress_handler.on_progress
|
||||
|
||||
def display():
|
||||
|
@ -45,15 +45,17 @@ def filter_versions(cp, versions):
|
||||
def scan_upstream_urls(cpv, urls, on_progress):
|
||||
versions = []
|
||||
|
||||
maxval = len(urls) + 5
|
||||
curval = 1
|
||||
progress_available = 70
|
||||
num_urls = sum([len(urls[fn]) for fn in urls])
|
||||
progress_increment = progress_available / num_urls
|
||||
|
||||
for filename in urls:
|
||||
curval += 1
|
||||
if on_progress:
|
||||
on_progress(maxval, curval)
|
||||
|
||||
for url in urls[filename]:
|
||||
|
||||
if on_progress and progress_available > 0:
|
||||
on_progress(increment=progress_increment)
|
||||
progress_available -= progress_increment
|
||||
|
||||
if not CONFIG['quiet'] and not CONFIG['format']:
|
||||
pp.uprint()
|
||||
output.einfo("SRC_URI is '%s'" % url)
|
||||
@ -82,15 +84,10 @@ def scan_upstream_urls(cpv, urls, on_progress):
|
||||
|
||||
cp, ver, rev = portage.pkgsplit(cpv)
|
||||
|
||||
curval += 1
|
||||
if on_progress:
|
||||
on_progress(maxval, curval)
|
||||
|
||||
result = filter_versions(cp, versions)
|
||||
|
||||
curval += 1
|
||||
if on_progress:
|
||||
on_progress(maxval, curval)
|
||||
if on_progress and progress_available > 0:
|
||||
on_progress(increment=progress_available)
|
||||
|
||||
return result
|
||||
|
||||
@ -118,9 +115,6 @@ def scan_upstream(query, on_progress=None):
|
||||
Scans the upstream searching new versions for the given query
|
||||
"""
|
||||
|
||||
maxval = 3
|
||||
curval = 0
|
||||
|
||||
matches = []
|
||||
|
||||
if query.endswith(".ebuild"):
|
||||
@ -159,9 +153,8 @@ def scan_upstream(query, on_progress=None):
|
||||
output.metadata("cp", pkg.cp, show=False)
|
||||
output.metadata("cpv", pkg.cpv, show=False)
|
||||
|
||||
curval += 1
|
||||
if on_progress:
|
||||
on_progress(maxval, curval)
|
||||
on_progress(increment=10)
|
||||
|
||||
if pkg.cp in BLACKLIST_PACKAGES:
|
||||
output.ewarn(
|
||||
@ -213,15 +206,10 @@ def scan_upstream(query, on_progress=None):
|
||||
scan_time = (datetime.now() - start_time).total_seconds()
|
||||
output.metadata("scan_time", scan_time, show=False)
|
||||
|
||||
curval += 1
|
||||
if on_progress:
|
||||
on_progress(maxval, curval)
|
||||
|
||||
result = scan_upstream_urls(pkg.cpv, urls, on_progress)
|
||||
|
||||
curval += 1
|
||||
if on_progress:
|
||||
on_progress(maxval, curval)
|
||||
on_progress(increment=10)
|
||||
|
||||
if len(result) > 0:
|
||||
if not (CONFIG['format'] or CONFIG['quiet']):
|
||||
|
Reference in New Issue
Block a user