Rev 3010: Add bzrlib.progress.CountedTask. in http://people.ubuntu.com/~robertc/baz2.0/nested-pb

Robert Collins robertc at robertcollins.net
Mon Nov 19 23:27:08 GMT 2007


At http://people.ubuntu.com/~robertc/baz2.0/nested-pb

------------------------------------------------------------
revno: 3010
revision-id:robertc at robertcollins.net-20071119232659-w1qo0wijx55zggb4
parent: robertc at robertcollins.net-20071119195948-n46szsvkgl0c9lj4
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Tue 2007-11-20 10:26:59 +1100
message:
  Add bzrlib.progress.CountedTask.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
  bzrlib/tests/test_progress.py  test_progress.py-20060308160359-978c397bc79b7fda
=== modified file 'NEWS'
--- a/NEWS	2007-11-17 18:07:42 +0000
+++ b/NEWS	2007-11-19 23:26:59 +0000
@@ -130,6 +130,9 @@
    * New module ``lru_cache`` providing a cache for use by tasks that need
      semi-random access to large amounts of data. (John A Meinel)
 
+   * Refactoring of ``bzrlib.progress`` to make it easier to extend, integrate
+     into graphical interfaces is in progress. (Robert Collins)
+
   TESTING:
 
 

=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py	2007-11-19 19:59:48 +0000
+++ b/bzrlib/progress.py	2007-11-19 23:26:59 +0000
@@ -26,6 +26,11 @@
 ProgressBarStack too if you need multiple levels of cooperating progress bars.
 Note that bzrlib's internal functions use the ui module, so if you are using
 bzrlib it really is best to use bzrlib.ui.ui_factory.
+
+Interesting classes for plugins and gui's that need to interoperate with this
+module:
+
+ * CountedTask: The most basic item of work.
 """
 
 # TODO: Optionally show elapsed time instead/as well as ETA; nicer
@@ -87,7 +92,31 @@
                                                 _progress_bar_types.keys())
         return _progress_bar_types[requested_bar_type](to_file=to_file, **kwargs)
 
- 
+
+class CountedTask(object):
+    """A task which can be worked on with no expected duration.
+    
+    An example of such a task is downloading content where we can tell how many
+    bytes have been downloaded, but not how many we are expecting.
+    """
+
+    def __init__(self, message):
+        """Create a CountedTask.
+        
+        :param message: The message for the task.
+        """
+        self._message = message
+        self.tick_size = 1
+        self.current = 0
+
+    def get_message(self):
+        """Get the message of this task.
+
+        :return: A string e.g. 'pulling'.
+        """
+        return self._message
+
+
 class ProgressBarStack(object):
     """A stack of progress bars."""
 

=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py	2007-11-19 00:44:03 +0000
+++ b/bzrlib/tests/test_progress.py	2007-11-19 23:26:59 +0000
@@ -19,11 +19,12 @@
 
 from bzrlib import errors
 from bzrlib.progress import (
-        DummyProgress,
         ChildProgress,
-        TTYProgressBar,
+        CountedTask,
         DotsProgressBar,
+        DummyProgress,
         ProgressBarStack,
+        TTYProgressBar,
         )
 from bzrlib.tests import TestCase
 
@@ -311,3 +312,13 @@
         out = _TTYStringIO()
         self.assertRaises(errors.InvalidProgressBarType, self.get_nested,
             out, 'xterm', 'nonexistant')
+
+
+class TestCountedTask(TestCase):
+
+    def test_construct_with_message(self):
+        message = 'transferring'
+        task = CountedTask(message)
+        self.assertEqual(message, task.get_message())
+        self.assertEqual(1, task.tick_size)
+        self.assertEqual(0, task.current)



More information about the bazaar-commits mailing list