summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2011-09-19 08:56:47 -0700
committerShawn O. Pearce <sop@google.com>2011-09-19 14:52:57 -0700
commit490d09a31415d3fd1b16f650188bfd8e701ae8e8 (patch)
treec7bff91f77533abf15f8b18b3c7e5fe0b3f5146e
parent13111b4e97d8cccdba5da974de0996994c64c7e5 (diff)
downloadgit-repo-490d09a31415d3fd1b16f650188bfd8e701ae8e8.tar.gz
Support units in progress messages
This allows our progress meter to be used for bytes transferred, by setting the units to KB or MB to let the user know the size. Change-Id: Ie8653d4a40d79439026c18bd51915845b2c5bba9 Signed-off-by: Shawn O. Pearce <sop@google.com>
-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()