From 7d093f0cb5f87696f627af664ce47edb67169125 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 27 May 2007 12:12:51 +0000 Subject: Add progress support to emaint (similar to wget's progress bar). svn path=/main/trunk/; revision=6639 --- bin/emaint | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/emaint b/bin/emaint index 0e9ba853d..c44bbe85a 100755 --- a/bin/emaint +++ b/bin/emaint @@ -1,6 +1,6 @@ #!/usr/bin/python -O -import sys, os +import sys, os, time from optparse import OptionParser, OptionValueError if not hasattr(__builtins__, "set"): from sets import Set as set @@ -12,7 +12,7 @@ except ImportError: sys.path.insert(0, osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")) import portage -import portage.const, portage.exception +import portage.const, portage.exception, portage.output class WorldHandler(object): def name(): @@ -132,6 +132,24 @@ class VdbKeyHandler(object): return errors +class ProgressHandler(object): + def __init__(self): + self.curval = 0 + self.maxval = 0 + self.last_update = 0 + self.min_display_latency = 0.2 + + def onProgress(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 + self.display() + + def display(self): + raise NotImplementedError(self) + def emaint_main(myargv): # TODO: Create a system that allows external modules to be added without @@ -191,11 +209,22 @@ def emaint_main(myargv): status = "Attempting to fix %s" func = "fix" - + isatty = sys.stdout.isatty() for task in tasks: print status % task.name() inst = task() - result = getattr(inst, func)() + onProgress = None + if isatty: + progressBar = portage.output.TermProgressBar() + progressHandler = ProgressHandler() + def display(): + progressBar.set(progressHandler.maxval, progressHandler.curval) + progressHandler.display = display + result = getattr(inst, func)(onProgress=progressHandler.onProgress) + if isatty: + # make sure the final progress is displayed + progressHandler.display() + print if result: print print "\n".join(result) -- cgit v1.2.3-1-g7c22