changeset 23907:63c7783a5928

progress: move update check into helper method
author Solomon Matthews <smat@fb.com>
date Sat, 17 Jan 2015 13:10:37 -0800
parents e0ae0a4e4c7b
children 5502bd79d052
files hgext/progress.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/progress.py	Sat Jan 17 13:09:33 2015 -0800
+++ b/hgext/progress.py	Sat Jan 17 13:10:37 2015 -0800
@@ -228,6 +228,17 @@
             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 @@
                 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: