1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
110
110
def __init__(self):
111
111
self._task_stack = []
114
def be_quiet(self, state):
115
"""Tell the UI to be more quiet, or not.
117
Typically this suppresses progress bars; the application may also look
118
at ui_factory.is_quiet().
113
122
def get_password(self, prompt='', **kwargs):
114
123
"""Prompt the user for a password.
126
135
raise NotImplementedError(self.get_password)
140
def make_output_stream(self, encoding=None, encoding_type=None):
141
"""Get a stream for sending out bulk text data.
143
This is used for commands that produce bulk text, such as log or diff
144
output, as opposed to user interaction. This should work even for
145
non-interactive user interfaces. Typically this goes to a decorated
146
version of stdout, but in a GUI it might be appropriate to send it to a
147
window displaying the text.
149
:param encoding: Unicode encoding for output; default is the
150
terminal encoding, which may be different from the user encoding.
151
(See get_terminal_encoding.)
153
:param encoding_type: How to handle encoding errors:
154
replace/strict/escape/exact. Default is replace.
156
# XXX: is the caller supposed to close the resulting object?
158
encoding = osutils.get_terminal_encoding()
159
if encoding_type is None:
160
encoding_type = 'replace'
161
out_stream = self._make_output_stream_explicit(encoding, encoding_type)
164
def _make_output_stream_explicit(self, encoding, encoding_type):
165
raise NotImplementedError("%s doesn't support make_output_stream"
166
% (self.__class__.__name__))
128
168
def nested_progress_bar(self):
129
169
"""Return a nested progress bar.
180
220
raise NotImplementedError(self.get_boolean)
222
def get_integer(self, prompt):
223
"""Get an integer from the user.
225
:param prompt: a message to prompt the user with. Could be a multi-line
226
prompt but without a terminating \n.
228
:return: A signed integer.
230
raise NotImplementedError(self.get_integer)
182
232
def make_progress_view(self):
183
233
"""Construct a new ProgressView object for this UI.
261
def log_transport_activity(self, display=False):
262
"""Write out whatever transport activity has been measured.
264
Implementations are allowed to do nothing, but it is useful if they can
265
write a line to the log file.
267
:param display: If False, only log to disk, if True also try to display
268
a message to the user.
271
# Default implementation just does nothing
211
274
def show_error(self, msg):
212
275
"""Show an error message (not an exception) to the user.
214
277
The message should not have an error prefix or trailing newline. That
215
will be added by the factory if appropriate.
278
will be added by the factory if appropriate.
217
280
raise NotImplementedError(self.show_error)
224
287
"""Show a warning to the user."""
225
288
raise NotImplementedError(self.show_warning)
290
def warn_cross_format_fetch(self, from_format, to_format):
291
"""Warn about a potentially slow cross-format transfer"""
292
# See <https://launchpad.net/bugs/456077> asking for a warning here
293
trace.warning("Doing on-the-fly conversion from %s to %s.\n"
294
"This may take some time. Upgrade the repositories to the "
295
"same format for better performance.\n" %
296
(from_format, to_format))
229
299
class SilentUIFactory(UIFactory):
245
315
def get_username(self, prompt, **kwargs):
318
def _make_output_stream_explicit(self, encoding, encoding_type):
319
return NullOutputStream(encoding)
248
321
def show_error(self, msg):
267
340
def get_boolean(self, prompt):
268
341
return self.responses.pop(0)
343
def get_integer(self, prompt):
344
return self.responses.pop(0)
270
346
def get_password(self, prompt='', **kwargs):
271
347
return self.responses.pop(0)
273
349
def get_username(self, prompt, **kwargs):
274
350
return self.responses.pop(0)
276
352
def assert_all_input_consumed(self):
277
353
if self.responses:
278
354
raise AssertionError("expected all input in %r to be consumed"
305
381
def show_transport_activity(self, transport, direction, byte_count):
384
def log_transport_activity(self, display=False):
388
class NullOutputStream(object):
389
"""Acts like a file, but discard all output."""
391
def __init__(self, encoding):
392
self.encoding = encoding
394
def write(self, data):
397
def writelines(self, data):