diff options
Diffstat (limited to 'progress.py')
-rw-r--r-- | progress.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/progress.py b/progress.py index d948654f..0dd5d1a8 100644 --- a/progress.py +++ b/progress.py | |||
@@ -21,7 +21,8 @@ from trace import IsTrace | |||
21 | _NOT_TTY = not os.isatty(2) | 21 | _NOT_TTY = not os.isatty(2) |
22 | 22 | ||
23 | class Progress(object): | 23 | class Progress(object): |
24 | def __init__(self, title, total=0, units=''): | 24 | def __init__(self, title, total=0, units='', print_newline=False, |
25 | always_print_percentage=False): | ||
25 | self._title = title | 26 | self._title = title |
26 | self._total = total | 27 | self._total = total |
27 | self._done = 0 | 28 | self._done = 0 |
@@ -29,6 +30,8 @@ class Progress(object): | |||
29 | self._start = time() | 30 | self._start = time() |
30 | self._show = False | 31 | self._show = False |
31 | self._units = units | 32 | self._units = units |
33 | self._print_newline = print_newline | ||
34 | self._always_print_percentage = always_print_percentage | ||
32 | 35 | ||
33 | def update(self, inc=1): | 36 | def update(self, inc=1): |
34 | self._done += inc | 37 | self._done += inc |
@@ -50,13 +53,14 @@ class Progress(object): | |||
50 | else: | 53 | else: |
51 | p = (100 * self._done) / self._total | 54 | p = (100 * self._done) / self._total |
52 | 55 | ||
53 | if self._lastp != p: | 56 | if self._lastp != p or self._always_print_percentage: |
54 | self._lastp = p | 57 | self._lastp = p |
55 | sys.stderr.write('\r%s: %3d%% (%d%s/%d%s) ' % ( | 58 | sys.stderr.write('\r%s: %3d%% (%d%s/%d%s)%s' % ( |
56 | self._title, | 59 | self._title, |
57 | p, | 60 | p, |
58 | self._done, self._units, | 61 | self._done, self._units, |
59 | self._total, self._units)) | 62 | self._total, self._units, |
63 | "\n" if self._print_newline else "")) | ||
60 | sys.stderr.flush() | 64 | sys.stderr.flush() |
61 | 65 | ||
62 | def end(self): | 66 | def end(self): |