Rev 2600: Don't show dots progress indicatiors in noninteractive mode in http://sourcefrog.net/bzr/progress

Martin Pool mbp at sourcefrog.net
Wed Jul 11 07:47:31 BST 2007


At http://sourcefrog.net/bzr/progress

------------------------------------------------------------
revno: 2600
revision-id: mbp at sourcefrog.net-20070711064730-pwnhisgp2caf7nar
parent: pqm at pqm.ubuntu.com-20070711041950-ci5yz9nyhbcdmuqv
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: progress
timestamp: Wed 2007-07-11 16:47:30 +1000
message:
  Don't show dots progress indicatiors in noninteractive mode
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-07-10 01:37:27 +0000
+++ b/NEWS	2007-07-11 06:47:30 +0000
@@ -6,7 +6,8 @@
 
   IMPROVEMENTS:
 
-    * None yet ...
+    * Don't show "dots" progress indicators when run non-interactively, such
+      as from cron.  (Martin Pool)
 
   LIBRARY API BREAKS:
 

=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py	2006-11-03 23:29:49 +0000
+++ b/bzrlib/progress.py	2007-07-11 06:47:30 +0000
@@ -50,6 +50,11 @@
 
 
 def _supports_progress(f):
+    """Detect if we can use pretty progress bars on the output stream f.
+
+    If this returns true we expect that a human may be looking at that 
+    output, and that we can repaint a line to update it.
+    """
     isatty = getattr(f, 'isatty', None)
     if isatty is None:
         return False
@@ -74,7 +79,7 @@
         if _supports_progress(to_file):
             return TTYProgressBar(to_file=to_file, **kwargs)
         else:
-            return DotsProgressBar(to_file=to_file, **kwargs)
+            return DummyProgress(to_file=to_file, **kwargs)
     else:
         # Minor sanitation to prevent spurious errors
         requested_bar_type = requested_bar_type.lower().strip()

=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py	2006-10-11 23:08:27 +0000
+++ b/bzrlib/tests/test_progress.py	2007-07-11 06:47:30 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 Canonical Ltd
+# Copyright (C) 2006, 2007 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -19,7 +19,8 @@
 
 from bzrlib import errors
 from bzrlib.progress import (
-        DummyProgress, ChildProgress,
+        DummyProgress,
+        ChildProgress,
         TTYProgressBar,
         DotsProgressBar,
         ProgressBarStack,
@@ -243,19 +244,27 @@
                          '\r                   \r',
                          out.getvalue())
 
+    def test_noninteractive_progress(self):
+        out = _NonTTYStringIO()
+        pb = self.get_nested(out, 'xterm')
+        self.assertIsInstance(pb, DummyProgress)
+        try:
+            pb.update('foo', 1, 2)
+            pb.update('bar', 2, 2)
+        finally:
+            pb.finished()
+        self.assertEqual('', out.getvalue())
+
     def test_dots_progress(self):
-        # Make sure the ProgressBarStack thinks it is
-        # not writing out to a terminal, and thus uses a 
-        # DotsProgressBar
+        # make sure we get the right progress bar when not on a terminal
         out = _NonTTYStringIO()
-        pb = self.get_nested(out, 'xterm')
+        pb = self.get_nested(out, 'xterm', 'dots')
         self.assertIsInstance(pb, DotsProgressBar)
         try:
             pb.update('foo', 1, 2)
             pb.update('bar', 2, 2)
         finally:
             pb.finished()
-
         self.assertEqual('foo: .'
                          '\nbar: .'
                          '\n',
@@ -267,16 +276,14 @@
         out = cStringIO.StringIO()
         pb = self.get_nested(out, 'xterm')
         pb.finished()
-        self.assertIsInstance(pb, DotsProgressBar)
+        self.assertIsInstance(pb, DummyProgress)
 
     def test_dumb_progress(self):
-        # Make sure the ProgressBarStack thinks it is writing out to a 
-        # terminal, but it is the emacs 'dumb' terminal, so it uses
-        # Dots
+        # using a terminal that can't do cursor movement
         out = _TTYStringIO()
         pb = self.get_nested(out, 'dumb')
         pb.finished()
-        self.assertIsInstance(pb, DotsProgressBar)
+        self.assertIsInstance(pb, DummyProgress)
 
     def test_progress_env_tty(self):
         # The environ variable BZR_PROGRESS_BAR controls what type of
@@ -290,13 +297,6 @@
         # Even though we are not a tty, the env_var will override
         self.assertIsInstance(pb, TTYProgressBar)
 
-    def test_progress_env_dots(self):
-        # Even though we are in a tty, the env_var will override
-        out = _TTYStringIO()
-        pb = self.get_nested(out, 'xterm', 'dots')
-        pb.finished()
-        self.assertIsInstance(pb, DotsProgressBar)
-
     def test_progress_env_none(self):
         # Even though we are in a valid tty, no progress
         out = _TTYStringIO()




More information about the bazaar-commits mailing list