Rev 4018: (jam) Fix the new progress code to handle pb.tick() properly. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Feb 18 21:23:27 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4018
revision-id: pqm at pqm.ubuntu.com-20090218212324-tz3ups4h8vg3j12t
parent: pqm at pqm.ubuntu.com-20090218132708-okubrahz9exvae9r
parent: john at arbash-meinel.com-20090218160236-vjuspv4igqlijq7y
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-02-18 21:23:24 +0000
message:
  (jam) Fix the new progress code to handle pb.tick() properly.
modified:
  bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
  bzrlib/tests/test_ui.py        test_ui.py-20051130162854-458e667a7414af09
  bzrlib/ui/text.py              text.py-20051130153916-2e438cffc8afc478
    ------------------------------------------------------------
    revno: 4017.1.1
    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.
    modified:
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
      bzrlib/tests/test_ui.py        test_ui.py-20051130162854-458e667a7414af09
      bzrlib/ui/text.py              text.py-20051130153916-2e438cffc8afc478
=== 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