aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-05-27 12:12:51 +0000
committerZac Medico <zmedico@gentoo.org>2007-05-27 12:12:51 +0000
commit7d093f0cb5f87696f627af664ce47edb67169125 (patch)
tree0d8f85f519474393f046666070411f39748e92d1 /bin/emaint
parentAdd a get_term_size() function that uses the curses module if available and o... (diff)
downloadportage-7d093f0cb5f87696f627af664ce47edb67169125.tar.gz
portage-7d093f0cb5f87696f627af664ce47edb67169125.tar.bz2
portage-7d093f0cb5f87696f627af664ce47edb67169125.zip
Add progress support to emaint (similar to wget's progress bar).
svn path=/main/trunk/; revision=6639
Diffstat (limited to 'bin/emaint')
-rwxr-xr-xbin/emaint37
1 files changed, 33 insertions, 4 deletions
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)