summaryrefslogtreecommitdiffstats
path: root/progress.py
diff options
context:
space:
mode:
Diffstat (limited to 'progress.py')
-rw-r--r--progress.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/progress.py b/progress.py
index 2ace7010..d948654f 100644
--- a/progress.py
+++ b/progress.py
@@ -21,13 +21,14 @@ from trace import IsTrace
21_NOT_TTY = not os.isatty(2) 21_NOT_TTY = not os.isatty(2)
22 22
23class Progress(object): 23class Progress(object):
24 def __init__(self, title, total=0): 24 def __init__(self, title, total=0, units=''):
25 self._title = title 25 self._title = title
26 self._total = total 26 self._total = total
27 self._done = 0 27 self._done = 0
28 self._lastp = -1 28 self._lastp = -1
29 self._start = time() 29 self._start = time()
30 self._show = False 30 self._show = False
31 self._units = units
31 32
32 def update(self, inc=1): 33 def update(self, inc=1):
33 self._done += inc 34 self._done += inc
@@ -51,11 +52,11 @@ class Progress(object):
51 52
52 if self._lastp != p: 53 if self._lastp != p:
53 self._lastp = p 54 self._lastp = p
54 sys.stderr.write('\r%s: %3d%% (%d/%d) ' % ( 55 sys.stderr.write('\r%s: %3d%% (%d%s/%d%s) ' % (
55 self._title, 56 self._title,
56 p, 57 p,
57 self._done, 58 self._done, self._units,
58 self._total)) 59 self._total, self._units))
59 sys.stderr.flush() 60 sys.stderr.flush()
60 61
61 def end(self): 62 def end(self):
@@ -69,9 +70,9 @@ class Progress(object):
69 sys.stderr.flush() 70 sys.stderr.flush()
70 else: 71 else:
71 p = (100 * self._done) / self._total 72 p = (100 * self._done) / self._total
72 sys.stderr.write('\r%s: %3d%% (%d/%d), done. \n' % ( 73 sys.stderr.write('\r%s: %3d%% (%d%s/%d%s), done. \n' % (
73 self._title, 74 self._title,
74 p, 75 p,
75 self._done, 76 self._done, self._units,
76 self._total)) 77 self._total, self._units))
77 sys.stderr.flush() 78 sys.stderr.flush()