Mercurial > hg
changeset 13132:24e3349cba8e
progress: refactor for readability and show XXs instead of 0mXXs.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Thu, 09 Dec 2010 17:33:40 -0600 |
parents | c9ae7e096994 |
children | 6320101a638c |
files | hgext/progress.py |
diffstat | 1 files changed, 14 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/progress.py Tue Oct 26 14:41:58 2010 +0300 +++ b/hgext/progress.py Thu Dec 09 17:33:40 2010 -0600 @@ -55,6 +55,19 @@ return (getattr(sys.stderr, 'isatty', None) and (sys.stderr.isatty() or ui.configbool('progress', 'assume-tty'))) +def fmtremaining(seconds): + if seconds < 60: + return _("%02ds") % (seconds) + minutes = seconds // 60 + if minutes < 60: + seconds -= minutes * 60 + return _("%dm%02ds") % (minutes, seconds) + # we're going to ignore seconds in this case + minutes += 1 + hours = minutes // 60 + minutes -= hours * 60 + return _("%dh%02dm") % (hours, minutes) + class progbar(object): def __init__(self, ui): self.ui = ui @@ -132,16 +145,7 @@ if elapsed > float( self.ui.config('progress', 'estimate', default=2)): seconds = (elapsed * (target - delta)) // delta + 1 - minutes = seconds // 60 - if minutes < 10: - seconds -= minutes * 60 - remaining = _("%dm%02ds") % (minutes, seconds) - else: - # we're going to ignore seconds in this case - minutes += 1 - hours = minutes // 60 - minutes -= hours * 60 - remaining = _("%dh%02dm") % (hours, minutes) + remaining = fmtremaining(seconds) progwidth -= len(remaining) + 1 tail = spacejoin(tail, remaining) amt = pos * progwidth // total