summaryrefslogtreecommitdiffstats
path: root/progress.py
diff options
context:
space:
mode:
Diffstat (limited to 'progress.py')
-rw-r--r--progress.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/progress.py b/progress.py
index 9222fcfc..3764b9e2 100644
--- a/progress.py
+++ b/progress.py
@@ -26,17 +26,14 @@ CSI_ERASE_LINE = '\x1b[2K'
26 26
27 27
28class Progress(object): 28class Progress(object):
29 def __init__(self, title, total=0, units='', print_newline=False, 29 def __init__(self, title, total=0, units='', print_newline=False):
30 always_print_percentage=False):
31 self._title = title 30 self._title = title
32 self._total = total 31 self._total = total
33 self._done = 0 32 self._done = 0
34 self._lastp = -1
35 self._start = time() 33 self._start = time()
36 self._show = False 34 self._show = False
37 self._units = units 35 self._units = units
38 self._print_newline = print_newline 36 self._print_newline = print_newline
39 self._always_print_percentage = always_print_percentage
40 37
41 def update(self, inc=1, msg=''): 38 def update(self, inc=1, msg=''):
42 self._done += inc 39 self._done += inc
@@ -58,18 +55,15 @@ class Progress(object):
58 sys.stderr.flush() 55 sys.stderr.flush()
59 else: 56 else:
60 p = (100 * self._done) / self._total 57 p = (100 * self._done) / self._total
61 58 sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % (
62 if self._lastp != p or self._always_print_percentage: 59 CSI_ERASE_LINE,
63 self._lastp = p 60 self._title,
64 sys.stderr.write('%s\r%s: %3d%% (%d%s/%d%s)%s%s%s' % ( 61 p,
65 CSI_ERASE_LINE, 62 self._done, self._units,
66 self._title, 63 self._total, self._units,
67 p, 64 ' ' if msg else '', msg,
68 self._done, self._units, 65 '\n' if self._print_newline else ''))
69 self._total, self._units, 66 sys.stderr.flush()
70 ' ' if msg else '', msg,
71 "\n" if self._print_newline else ""))
72 sys.stderr.flush()
73 67
74 def end(self): 68 def end(self):
75 if _NOT_TTY or IsTrace() or not self._show: 69 if _NOT_TTY or IsTrace() or not self._show: