Rev 3012: Add bzrlib.progress.DotsTaskDisplay. in http://people.ubuntu.com/~robertc/baz2.0/nested-pb
Robert Collins
robertc at robertcollins.net
Tue Nov 20 00:02:47 GMT 2007
At http://people.ubuntu.com/~robertc/baz2.0/nested-pb
------------------------------------------------------------
revno: 3012
revision-id:robertc at robertcollins.net-20071120000238-bitv7u6kda5lmv5w
parent: robertc at robertcollins.net-20071119235143-p3h8sxxd2tlw46ke
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Tue 2007-11-20 11:02:38 +1100
message:
Add bzrlib.progress.DotsTaskDisplay.
modified:
bzrlib/progress.py progress.py-20050610070202-df9faaab791964c0
bzrlib/tests/test_progress.py test_progress.py-20060308160359-978c397bc79b7fda
=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py 2007-11-19 23:51:43 +0000
+++ b/bzrlib/progress.py 2007-11-20 00:02:38 +0000
@@ -259,15 +259,37 @@
_progress_bar_types['none'] = DummyProgress
-class SilentTaskDisplay(object):
- """A TaskDisplay that performs no output."""
+class TaskDisplay(object):
+ """Display a task in some medium."""
def __init__(self, task):
- """Create a SilentTaskDisplay."""
+ """Create a TaskDisplay."""
self._task = task
def task_changed(self):
- """Notify the display that the task has changed."""
+ """Update the display due to a change in the task."""
+ raise NotImplementedError(self.task_changed)
+
+
+class DotsTaskDisplay(TaskDisplay):
+ """Display the task on a file stream using dots to mark activity."""
+
+ def __init__(self, task, stream):
+ TaskDisplay.__init__(self, task)
+ self._stream = stream
+
+ def task_changed(self):
+ # When the task changes, a dots display should output each message it
+ # sees once, then dots until a new message is shown. Messages are shown
+ # at the beginning of a line.
+ self._stream.write(self._task.get_message() + ':')
+
+
+class SilentTaskDisplay(TaskDisplay):
+ """A TaskDisplay that performs no output."""
+
+ def task_changed(self):
+ pass
class DotsProgressBar(_BaseProgressBar):
=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py 2007-11-19 23:51:43 +0000
+++ b/bzrlib/tests/test_progress.py 2007-11-20 00:02:38 +0000
@@ -22,6 +22,7 @@
ChildProgress,
CountedTask,
DotsProgressBar,
+ DotsTaskDisplay,
DummyProgress,
ProgressBarStack,
SilentTaskDisplay,
@@ -336,3 +337,20 @@
display = SilentTaskDisplay(task)
# We cannot really tell if anything is output, but the API should work.
display.task_changed()
+
+
+class TestDotsTaskDisplay(TestCase):
+
+ def test_construct(self):
+ task = CountedTask('message')
+ output = StringIO()
+ display = DotsTaskDisplay(task, output)
+
+ def test_task_changed(self):
+ task = CountedTask('message')
+ output = StringIO()
+ display = DotsTaskDisplay(task, output)
+ # The first change will display the message
+ display.task_changed()
+ self.assertEqual('message:', output.getvalue())
+
More information about the bazaar-commits
mailing list