diff options
Diffstat (limited to 'hgext/progress.py')
-rw-r--r-- | hgext/progress.py | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/hgext/progress.py b/hgext/progress.py index 3cc3747..652fafe 100644 --- a/hgext/progress.py +++ b/hgext/progress.py @@ -2,8 +2,19 @@ # # Copyright (C) 2010 Augie Fackler <durin42@gmail.com> # -# This software may be used and distributed according to the terms of the -# GNU General Public License version 2 or any later version. +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """show progress bars for some actions @@ -16,9 +27,6 @@ The following settings are available:: [progress] delay = 3 # number of seconds (float) before showing the progress bar - changedelay = 1 # changedelay: minimum delay before showing a new topic. - # If set to less than 3 * refresh, that value will - # be used instead. refresh = 0.1 # time in seconds between refreshes of the progress bar format = topic bar number estimate # format of the progress bar width = <none> # if set, the maximum width of the progress information @@ -38,14 +46,14 @@ characters. import sys import time +from mercurial import util from mercurial.i18n import _ -testedwith = 'internal' def spacejoin(*args): return ' '.join(s for s in args if s) def shouldprint(ui): - return ui._isatty(sys.stderr) or ui.configbool('progress', 'assume-tty') + return (util.isatty(sys.stderr) or ui.configbool('progress', 'assume-tty')) def fmtremaining(seconds): if seconds < 60: @@ -97,13 +105,9 @@ class progbar(object): self.printed = False self.lastprint = time.time() + float(self.ui.config( 'progress', 'delay', default=3)) - self.lasttopic = None self.indetcount = 0 self.refresh = float(self.ui.config( 'progress', 'refresh', default=0.1)) - self.changedelay = max(3 * self.refresh, - float(self.ui.config( - 'progress', 'changedelay', default=1))) self.order = self.ui.configlist( 'progress', 'format', default=['topic', 'bar', 'number', 'estimate']) @@ -180,7 +184,6 @@ class progbar(object): else: out = spacejoin(head, tail) sys.stderr.write('\r' + out[:termwidth]) - self.lasttopic = topic sys.stderr.flush() def clear(self): @@ -237,7 +240,7 @@ class progbar(object): # truncate the list of topics assuming all topics within # this one are also closed if topic in self.topics: - self.topics = self.topics[:self.topics.index(topic)] + self.topics = self.topics[:self.topics.index(topic)] else: if topic not in self.topics: self.starttimes[topic] = now @@ -245,36 +248,24 @@ class progbar(object): self.topics.append(topic) self.topicstates[topic] = pos, item, unit, total if now - self.lastprint >= self.refresh and self.topics: - if (self.lasttopic is None # first time we printed - # not a topic change - or topic == self.lasttopic - # it's been long enough we should print anyway - or now - self.lastprint >= self.changedelay): - self.lastprint = now - self.show(now, topic, *self.topicstates[topic]) - -_singleton = None + self.lastprint = now + self.show(now, topic, *self.topicstates[topic]) def uisetup(ui): - global _singleton class progressui(ui.__class__): _progbar = None - def _quiet(self): - return self.debugflag or self.quiet - def progress(self, *args, **opts): - if not self._quiet(): - self._progbar.progress(*args, **opts) + self._progbar.progress(*args, **opts) return super(progressui, self).progress(*args, **opts) def write(self, *args, **opts): - if not self._quiet() and self._progbar.printed: + if self._progbar.printed: self._progbar.clear() return super(progressui, self).write(*args, **opts) def write_err(self, *args, **opts): - if not self._quiet() and self._progbar.printed: + if self._progbar.printed: self._progbar.clear() return super(progressui, self).write_err(*args, **opts) @@ -287,9 +278,7 @@ def uisetup(ui): # we instantiate one globally shared progress bar to avoid # competing progress bars when multiple UI objects get created if not progressui._progbar: - if _singleton is None: - _singleton = progbar(ui) - progressui._progbar = _singleton + progressui._progbar = progbar(ui) def reposetup(ui, repo): uisetup(repo.ui) |