mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
13111b4e97
commit
490d09a314
15
progress.py
15
progress.py
@ -21,13 +21,14 @@ from trace import IsTrace
|
|||||||
_NOT_TTY = not os.isatty(2)
|
_NOT_TTY = not os.isatty(2)
|
||||||
|
|
||||||
class Progress(object):
|
class Progress(object):
|
||||||
def __init__(self, title, total=0):
|
def __init__(self, title, total=0, units=''):
|
||||||
self._title = title
|
self._title = title
|
||||||
self._total = total
|
self._total = total
|
||||||
self._done = 0
|
self._done = 0
|
||||||
self._lastp = -1
|
self._lastp = -1
|
||||||
self._start = time()
|
self._start = time()
|
||||||
self._show = False
|
self._show = False
|
||||||
|
self._units = units
|
||||||
|
|
||||||
def update(self, inc=1):
|
def update(self, inc=1):
|
||||||
self._done += inc
|
self._done += inc
|
||||||
@ -51,11 +52,11 @@ class Progress(object):
|
|||||||
|
|
||||||
if self._lastp != p:
|
if self._lastp != p:
|
||||||
self._lastp = p
|
self._lastp = p
|
||||||
sys.stderr.write('\r%s: %3d%% (%d/%d) ' % (
|
sys.stderr.write('\r%s: %3d%% (%d%s/%d%s) ' % (
|
||||||
self._title,
|
self._title,
|
||||||
p,
|
p,
|
||||||
self._done,
|
self._done, self._units,
|
||||||
self._total))
|
self._total, self._units))
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
@ -69,9 +70,9 @@ class Progress(object):
|
|||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
else:
|
else:
|
||||||
p = (100 * self._done) / self._total
|
p = (100 * self._done) / self._total
|
||||||
sys.stderr.write('\r%s: %3d%% (%d/%d), done. \n' % (
|
sys.stderr.write('\r%s: %3d%% (%d%s/%d%s), done. \n' % (
|
||||||
self._title,
|
self._title,
|
||||||
p,
|
p,
|
||||||
self._done,
|
self._done, self._units,
|
||||||
self._total))
|
self._total, self._units))
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user