Rev 4910: Play around with the ui display a bit more. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes

John Arbash Meinel john at arbash-meinel.com
Fri Dec 18 17:42:32 GMT 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes

------------------------------------------------------------
revno: 4910
revision-id: john at arbash-meinel.com-20091218174230-2xrmkkbw4f5idufr
parent: john at arbash-meinel.com-20091218171934-l7og4as9pj7pyqr5
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-dbytes
timestamp: Fri 2009-12-18 11:42:30 -0600
message:
  Play around with the ui display a bit more.
  Went through a lot of permutations, I think I like this one the most.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_uifactory/__init__.py'
--- a/bzrlib/tests/per_uifactory/__init__.py	2009-12-18 17:19:34 +0000
+++ b/bzrlib/tests/per_uifactory/__init__.py	2009-12-18 17:42:30 +0000
@@ -90,6 +90,7 @@
         t = transport.get_transport('memory:///')
         self.factory.report_transport_activity(t, 1000, 'write')
         self.factory.report_transport_activity(t, 2000, 'read')
+        self.factory.report_transport_activity(t, 4000, None)
         self.factory.log_transport_activity()
         self._check_log_transport_activity_noarg()
         self.factory.log_transport_activity(display=True)
@@ -166,7 +167,8 @@
     def _check_log_transport_activity_display(self):
         self.assertEqual('', self.stdout.getvalue())
         # Displaying the result should write to the progress stream
-        self.assertEqual('Total byte count: 0.003MiB (3000B)\n',
+        self.assertEqual('Transferred: 0.007MiB'
+                         ' (r:0.002MiB w:0.001MiB u:0.004MiB)\n',
                          self.stderr.getvalue())
 
 

=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py	2009-12-18 17:19:34 +0000
+++ b/bzrlib/ui/text.py	2009-12-18 17:42:30 +0000
@@ -264,6 +264,7 @@
         self._last_task = None
         self._total_byte_count = 0
         self._bytes_since_update = 0
+        self._bytes_by_direction = {'unknown': 0, 'read': 0, 'write': 0}
         self._fraction = 0
         # force the progress bar to be off, as at the moment it doesn't 
         # correspond reliably to overall command progress
@@ -381,6 +382,10 @@
         # here.
         self._total_byte_count += byte_count
         self._bytes_since_update += byte_count
+        if direction in self._bytes_by_direction:
+            self._bytes_by_direction[direction] += byte_count
+        else:
+            self._bytes_by_direction['unknown'] += byte_count
         if not self._have_output:
             # As a workaround for <https://launchpad.net/bugs/321935> we only
             # show transport activity when there's already a progress bar
@@ -408,14 +413,27 @@
             self._last_transport_msg = msg
             self._repaint()
 
+    def _format_bytes_by_direction(self):
+        msg = ('Transferred: %.3fMiB'
+               ' (r:%.3fMiB w:%.3fMiB'
+               % (self._total_byte_count / 1024. / 1024.,
+                  self._bytes_by_direction['read'] / 1024. / 1024.,
+                  self._bytes_by_direction['write'] / 1024. / 1024.,
+                 ))
+        if self._bytes_by_direction['unknown'] > 0:
+            msg += ' u:%.3fMiB)' % (
+                self._bytes_by_direction['unknown'] / 1024. / 1024.
+                )
+        else:
+            msg += ')'
+        return msg
+
     def log_transport_activity(self, display=False):
-        byte_message = 'Total byte count: %.3fMiB (%dB)' % (
-                        self._total_byte_count / 1024. / 1024,
-                        self._total_byte_count)
-        trace.mutter(byte_message)
+        msg = self._format_bytes_by_direction()
+        trace.mutter(msg)
         if display:
             self.clear()
-            self._term_file.write('%s\n' % (byte_message,))
+            self._term_file.write(msg + '\n')
 
 
 class TextUIOutputStream(object):



More information about the bazaar-commits mailing list