Rev 4018: Get a pb.tick() to work after calling pb.update() in lp:///~jameinel/bzr/pb_tick

John Arbash Meinel john at arbash-meinel.com
Wed Feb 18 16:02:48 GMT 2009


At lp:///~jameinel/bzr/pb_tick

------------------------------------------------------------
revno: 4018
revision-id: john at arbash-meinel.com-20090218160236-vjuspv4igqlijq7y
parent: pqm at pqm.ubuntu.com-20090218132708-okubrahz9exvae9r
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: pb_tick
timestamp: Wed 2009-02-18 10:02:36 -0600
message:
  Get a pb.tick() to work after calling pb.update()
  
  Calling pb.tick() does an update with current_cnt = None.
  This often is fine, as long as you haven't called update() before
  with a total_count. Once total_count is set, then there were
  code paths that didn't handle missing current_count.
-------------- next part --------------
=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py	2009-01-21 06:01:17 +0000
+++ b/bzrlib/progress.py	2009-02-18 16:02:36 +0000
@@ -107,9 +107,9 @@
 
     def _overall_completion_fraction(self, child_fraction=0.0):
         """Return fractional completion of this task and its parents
-        
+
         Returns None if no completion can be computed."""
-        if self.total_cnt:
+        if self.current_cnt is not None and self.total_cnt:
             own_fraction = (float(self.current_cnt) + child_fraction) / self.total_cnt
         else:
             own_fraction = None

=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py	2009-01-21 06:01:17 +0000
+++ b/bzrlib/tests/test_ui.py	2009-02-18 16:02:36 +0000
@@ -21,6 +21,7 @@
 from StringIO import StringIO
 import re
 import sys
+import time
 
 import bzrlib
 import bzrlib.errors as errors
@@ -237,3 +238,14 @@
             r"what do you want\? \[y/n\]: what do you want\? \[y/n\]: ")
         # stdin should have been totally consumed
         self.assertEqual('', factory.stdin.readline())
+
+    def test_text_tick_after_update(self):
+        ui_factory = TextUIFactory(stdout=StringIO(), stderr=StringIO())
+        pb = ui_factory.nested_progress_bar()
+        try:
+            pb.update('task', 0, 3)
+            # Reset the clock, so that it actually tries to repaint itself
+            ui_factory._progress_view._last_repaint = time.time() - 1.0
+            pb.tick()
+        finally:
+            pb.finished()

=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py	2009-01-21 05:49:18 +0000
+++ b/bzrlib/ui/text.py	2009-02-18 16:02:36 +0000
@@ -162,7 +162,7 @@
     def _format_task(self, task):
         if not task.show_count:
             s = ''
-        elif task.total_cnt is not None:
+        elif task.current_cnt is not None and task.total_cnt is not None:
             s = ' %d/%d' % (task.current_cnt, task.total_cnt)
         elif task.current_cnt is not None:
             s = ' %d' % (task.current_cnt)



More information about the bazaar-commits mailing list