# HG changeset patch # User Solomon Matthews # Date 2015-01-17 21:10:37 # Node ID 63c7783a59281997a7bf9d50c468caa4f1c92177 # Parent e0ae0a4e4c7b3d502159f0f44cdd5b2065876b1e progress: move update check into helper method diff --git a/hgext/progress.py b/hgext/progress.py --- a/hgext/progress.py +++ b/hgext/progress.py @@ -228,6 +228,17 @@ class progbar(object): return _('%d %s/sec') % (delta / elapsed, unit) return '' + def _oktoprint(self, now): + '''Check if conditions are met to print - e.g. changedelay elapsed''' + if (self.lasttopic is None # first time we printed + # not a topic change + or self.curtopic == self.lasttopic + # it's been long enough we should print anyway + or now - self.lastprint >= self.changedelay): + return True + else: + return False + def progress(self, topic, pos, item='', unit='', total=None): now = time.time() try: @@ -258,11 +269,7 @@ class progbar(object): self.topicstates[topic] = pos, item, unit, total self.curtopic = topic 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): + if self._oktoprint(now): self.lastprint = now self.show(now, topic, *self.topicstates[topic]) finally: