Rev 4907: Basic implementation of logging bytes transferred when bzr exits. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes

John Arbash Meinel john at arbash-meinel.com
Fri Dec 18 16:39:23 GMT 2009


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

------------------------------------------------------------
revno: 4907
revision-id: john at arbash-meinel.com-20091218163921-tcltjarx4pxxm08y
parent: pqm at pqm.ubuntu.com-20091217110447-6gebnkhfriqm2xia
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-dbytes
timestamp: Fri 2009-12-18 10:39:21 -0600
message:
  Basic implementation of logging bytes transferred when bzr exits.
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2009-12-09 05:47:32 +0000
+++ b/bzrlib/commands.py	2009-12-18 16:39:21 +0000
@@ -1103,6 +1103,7 @@
             raise errors.BzrError("argv should be list of unicode strings.")
         argv = new_argv
     ret = run_bzr_catch_errors(argv)
+    bzrlib.ui.ui_factory.log_transport_activity('bytes' in debug.debug_flags)
     trace.mutter("return code %d", ret)
     osutils.report_extension_load_failures()
     return ret

=== modified file 'bzrlib/help_topics/en/debug-flags.txt'
--- a/bzrlib/help_topics/en/debug-flags.txt	2009-12-11 21:57:03 +0000
+++ b/bzrlib/help_topics/en/debug-flags.txt	2009-12-18 16:39:21 +0000
@@ -5,6 +5,7 @@
 prefix) put in the ``debug_flags`` variable in ``bazaar.conf``.
 
 -Dauth            Trace authentication sections used.
+-Dbytes           Print out how many bytes were transferred
 -Ddirstate        Trace dirstate activity (verbose!)
 -Derror           Instead of normal error handling, always print a traceback
                   on error.

=== modified file 'bzrlib/ui/__init__.py'
--- a/bzrlib/ui/__init__.py	2009-12-10 16:54:28 +0000
+++ b/bzrlib/ui/__init__.py	2009-12-18 16:39:21 +0000
@@ -246,6 +246,19 @@
         """
         pass
 
+    def log_transport_activity(self, display=False):
+        """Write out whatever transport activity has been measured.
+
+        Implementations are allowed to do nothing, but it is useful if they can
+        write a line to the log file.
+
+        :param display: If False, only log to disk, if True also try to display
+            a message to the user.
+        :return: None
+        """
+        # Default implementation just does nothing
+        pass
+
     def show_error(self, msg):
         """Show an error message (not an exception) to the user.
         
@@ -345,3 +358,6 @@
 
     def show_transport_activity(self, transport, direction, byte_count):
         pass
+
+    def log_transport_activity(self, display=False):
+        pass

=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py	2009-12-16 10:54:55 +0000
+++ b/bzrlib/ui/text.py	2009-12-18 16:39:21 +0000
@@ -32,6 +32,7 @@
     progress,
     osutils,
     symbol_versioning,
+    trace,
     )
 
 """)
@@ -203,6 +204,12 @@
         self._progress_view.show_transport_activity(transport,
             direction, byte_count)
 
+    def log_transport_activity(self, display=False):
+        """See UIFactory.log_transport_activity()"""
+        log = getattr(self._progress_view, 'log_transport_activity', None)
+        if log is not None:
+            log(display=display)
+
     def show_error(self, msg):
         self.clear_term()
         self.stderr.write("bzr: error: %s\n" % msg)
@@ -401,6 +408,14 @@
             self._last_transport_msg = msg
             self._repaint()
 
+    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)
+        if display:
+            self._term_file.write('\n%s\n' % (byte_message,))
+
 
 class TextUIOutputStream(object):
     """Decorates an output stream so that the terminal is cleared before writing.



More information about the bazaar-commits mailing list