1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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().
122
113
def get_password(self, prompt='', **kwargs):
123
114
"""Prompt the user for a password.
135
126
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__))
168
128
def nested_progress_bar(self):
169
129
"""Return a nested progress bar.
220
180
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)
232
182
def make_progress_view(self):
233
183
"""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
274
211
def show_error(self, msg):
275
212
"""Show an error message (not an exception) to the user.
277
214
The message should not have an error prefix or trailing newline. That
278
will be added by the factory if appropriate.
215
will be added by the factory if appropriate.
280
217
raise NotImplementedError(self.show_error)
287
224
"""Show a warning to the user."""
288
225
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))
299
229
class SilentUIFactory(UIFactory):
315
245
def get_username(self, prompt, **kwargs):
318
def _make_output_stream_explicit(self, encoding, encoding_type):
319
return NullOutputStream(encoding)
321
248
def show_error(self, msg):
340
267
def get_boolean(self, prompt):
341
268
return self.responses.pop(0)
343
def get_integer(self, prompt):
344
return self.responses.pop(0)
346
270
def get_password(self, prompt='', **kwargs):
347
271
return self.responses.pop(0)
349
273
def get_username(self, prompt, **kwargs):
350
274
return self.responses.pop(0)
352
276
def assert_all_input_consumed(self):
353
277
if self.responses:
354
278
raise AssertionError("expected all input in %r to be consumed"
381
305
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):