Merge lp:~mbp/bzr/320035-progress-quiet into lp:bzr

Proposed by Martin Pool
Status: Merged
Approved by: Andrew Bennetts
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~mbp/bzr/320035-progress-quiet
Merge into: lp:bzr
Diff against target: 175 lines (+51/-9)
6 files modified
NEWS (+3/-0)
bzrlib/tests/per_uifactory/__init__.py (+6/-0)
bzrlib/tests/test_ui.py (+12/-1)
bzrlib/trace.py (+4/-4)
bzrlib/ui/__init__.py (+12/-0)
bzrlib/ui/text.py (+14/-4)
To merge this branch: bzr merge lp:~mbp/bzr/320035-progress-quiet
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+17440@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

--quiet now turns off the progress bar.

Revision history for this message
Andrew Bennetts (spiv) wrote :

Thanks for making --quiet actually approximate silence :)

The code seems ok to me. There's some trivial conflicts, you should try my news_merge plugin ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-01-15 07:36:10 +0000
3+++ NEWS 2010-01-15 07:47:13 +0000
4@@ -93,6 +93,9 @@
5 * Listen to the SIGWINCH signal to update the terminal width.
6 (Vincent Ladeuil, #316357)
7
8+* Progress bars are now hidden when ``--quiet`` is given.
9+ (Martin Pool, #320035)
10+
11 * ``SilentUIFactory`` now supports ``make_output_stream`` and discards
12 whatever is written to it. This un-breaks some plugin tests that
13 depended on this behaviour.
14
15=== modified file 'bzrlib/tests/per_uifactory/__init__.py'
16--- bzrlib/tests/per_uifactory/__init__.py 2010-01-14 08:20:18 +0000
17+++ bzrlib/tests/per_uifactory/__init__.py 2010-01-15 07:47:13 +0000
18@@ -56,6 +56,12 @@
19 the concrete subclasses should be.
20 """
21
22+ def test_be_quiet(self):
23+ self.factory.be_quiet(True)
24+ self.assertEquals(True, self.factory.is_quiet())
25+ self.factory.be_quiet(False)
26+ self.assertEquals(False, self.factory.is_quiet())
27+
28 def test_note(self):
29 self.factory.note("a note to the user")
30 self._check_note("a note to the user")
31
32=== modified file 'bzrlib/tests/test_ui.py'
33--- bzrlib/tests/test_ui.py 2009-12-10 16:54:28 +0000
34+++ bzrlib/tests/test_ui.py 2010-01-15 07:47:12 +0000
35@@ -1,4 +1,4 @@
36-# Copyright (C) 2005, 2008, 2009 Canonical Ltd
37+# Copyright (C) 2005, 2008, 2009, 2010 Canonical Ltd
38 #
39 # This program is free software; you can redistribute it and/or modify
40 # it under the terms of the GNU General Public License as published by
41@@ -248,6 +248,17 @@
42 finally:
43 pb.finished()
44
45+ def test_quietness(self):
46+ os.environ['BZR_PROGRESS_BAR'] = 'text'
47+ ui_factory = _mod_ui_text.TextUIFactory(None,
48+ test_progress._TTYStringIO(),
49+ test_progress._TTYStringIO())
50+ self.assertIsInstance(ui_factory._progress_view,
51+ _mod_ui_text.TextProgressView)
52+ ui_factory.be_quiet(True)
53+ self.assertIsInstance(ui_factory._progress_view,
54+ _mod_ui_text.NullProgressView)
55+
56
57 class TestTextUIOutputStream(tests.TestCase):
58 """Tests for output stream that synchronizes with progress bar."""
59
60=== modified file 'bzrlib/trace.py'
61--- bzrlib/trace.py 2010-01-12 06:30:41 +0000
62+++ bzrlib/trace.py 2010-01-15 07:47:13 +0000
63@@ -14,7 +14,7 @@
64 # along with this program; if not, write to the Free Software
65 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
66
67-"""Messages and logging for bazaar-ng.
68+"""Messages and logging.
69
70 Messages are supplied by callers as a string-formatting template, plus values
71 to be inserted into it. The actual %-formatting is deferred to the log
72@@ -33,8 +33,7 @@
73
74 Output to stderr depends on the mode chosen by the user. By default, messages
75 of info and above are sent out, which results in progress messages such as the
76-list of files processed by add and commit. In quiet mode, only warnings and
77-above are shown. In debug mode, stderr gets debug messages too.
78+list of files processed by add and commit. In debug mode, stderr gets debug messages too.
79
80 Errors that terminate an operation are generally passed back as exceptions;
81 others may be just emitted as messages.
82@@ -83,6 +82,7 @@
83 osutils,
84 plugin,
85 symbol_versioning,
86+ ui,
87 )
88 """)
89
90@@ -365,6 +365,7 @@
91 global _verbosity_level
92 _verbosity_level = level
93 _update_logging_level(level < 0)
94+ ui.ui_factory.be_quiet(level < 0)
95
96
97 def get_verbosity_level():
98@@ -376,7 +377,6 @@
99
100
101 def be_quiet(quiet=True):
102- # Perhaps this could be deprecated now ...
103 if quiet:
104 set_verbosity_level(-1)
105 else:
106
107=== modified file 'bzrlib/ui/__init__.py'
108--- bzrlib/ui/__init__.py 2010-01-15 07:00:49 +0000
109+++ bzrlib/ui/__init__.py 2010-01-15 07:47:12 +0000
110@@ -109,6 +109,15 @@
111
112 def __init__(self):
113 self._task_stack = []
114+ self._quiet = False
115+
116+ def be_quiet(self, state):
117+ """Tell the UI to be more quiet, or not.
118+
119+ Typically this suppresses progress bars; the application may also look
120+ at ui_factory.is_quiet().
121+ """
122+ self._quiet = state
123
124 def get_password(self, prompt='', **kwargs):
125 """Prompt the user for a password.
126@@ -125,6 +134,9 @@
127 """
128 raise NotImplementedError(self.get_password)
129
130+ def is_quiet(self):
131+ return self._quiet
132+
133 def make_output_stream(self, encoding=None, encoding_type=None):
134 """Get a stream for sending out bulk text data.
135
136
137=== modified file 'bzrlib/ui/text.py'
138--- bzrlib/ui/text.py 2010-01-05 04:30:07 +0000
139+++ bzrlib/ui/text.py 2010-01-15 07:47:12 +0000
140@@ -1,4 +1,4 @@
141-# Copyright (C) 2005, 2008, 2009 Canonical Ltd
142+# Copyright (C) 2005, 2008, 2009, 2010 Canonical Ltd
143 #
144 # This program is free software; you can redistribute it and/or modify
145 # it under the terms of the GNU General Public License as published by
146@@ -61,6 +61,12 @@
147 # paints progress, network activity, etc
148 self._progress_view = self.make_progress_view()
149
150+ def be_quiet(self, state):
151+ if state and not self._quiet:
152+ self.clear_term()
153+ UIFactory.be_quiet(self, state)
154+ self._progress_view = self.make_progress_view()
155+
156 def clear_term(self):
157 """Prepare the terminal for output.
158
159@@ -146,9 +152,13 @@
160 def make_progress_view(self):
161 """Construct and return a new ProgressView subclass for this UI.
162 """
163- # if the user specifically requests either text or no progress bars,
164- # always do that. otherwise, guess based on $TERM and tty presence.
165- if os.environ.get('BZR_PROGRESS_BAR') == 'text':
166+ # with --quiet, never any progress view
167+ # <https://bugs.edge.launchpad.net/bzr/+bug/320035>. Otherwise if the
168+ # user specifically requests either text or no progress bars, always
169+ # do that. otherwise, guess based on $TERM and tty presence.
170+ if self.is_quiet():
171+ return NullProgressView()
172+ elif os.environ.get('BZR_PROGRESS_BAR') == 'text':
173 return TextProgressView(self.stderr)
174 elif os.environ.get('BZR_PROGRESS_BAR') == 'none':
175 return NullProgressView()