progress: move update check into helper method
authorSolomon Matthews <smat@fb.com>
Sat, 17 Jan 2015 13:10:37 -0800
changeset 23907 63c7783a5928
parent 23906 e0ae0a4e4c7b
child 23908 5502bd79d052
progress: move update check into helper method
hgext/progress.py
--- 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: