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
126
126
raise NotImplementedError(self.get_password)
128
def make_output_stream(self, encoding=None, encoding_type=None):
129
"""Get a stream for sending out bulk text data.
131
This is used for commands that produce bulk text, such as log or diff
132
output, as opposed to user interaction. This should work even for
133
non-interactive user interfaces. Typically this goes to a decorated
134
version of stdout, but in a GUI it might be appropriate to send it to a
135
window displaying the text.
137
:param encoding: Unicode encoding for output; default is the
138
terminal encoding, which may be different from the user encoding.
139
(See get_terminal_encoding.)
141
:param encoding_type: How to handle encoding errors:
142
replace/strict/escape/exact. Default is replace.
144
# XXX: is the caller supposed to close the resulting object?
146
encoding = osutils.get_terminal_encoding()
147
if encoding_type is None:
148
encoding_type = 'replace'
149
out_stream = self._make_output_stream_explicit(encoding, encoding_type)
152
def _make_output_stream_explicit(self, encoding, encoding_type):
153
raise NotImplementedError("%s doesn't support make_output_stream"
154
% (self.__class__.__name__))
156
128
def nested_progress_bar(self):
157
129
"""Return a nested progress bar.
208
180
raise NotImplementedError(self.get_boolean)
210
def get_integer(self, prompt):
211
"""Get an integer from the user.
213
:param prompt: a message to prompt the user with. Could be a multi-line
214
prompt but without a terminating \n.
216
:return: A signed integer.
218
raise NotImplementedError(self.get_integer)
220
182
def make_progress_view(self):
221
183
"""Construct a new ProgressView object for this UI.
249
def log_transport_activity(self, display=False):
250
"""Write out whatever transport activity has been measured.
252
Implementations are allowed to do nothing, but it is useful if they can
253
write a line to the log file.
255
:param display: If False, only log to disk, if True also try to display
256
a message to the user.
259
# Default implementation just does nothing
262
211
def show_error(self, msg):
263
212
"""Show an error message (not an exception) to the user.
296
245
def get_username(self, prompt, **kwargs):
299
def _make_output_stream_explicit(self, encoding, encoding_type):
300
return NullOutputStream(encoding)
302
248
def show_error(self, msg):
321
267
def get_boolean(self, prompt):
322
268
return self.responses.pop(0)
324
def get_integer(self, prompt):
325
return self.responses.pop(0)
327
270
def get_password(self, prompt='', **kwargs):
328
271
return self.responses.pop(0)
330
273
def get_username(self, prompt, **kwargs):
331
274
return self.responses.pop(0)
333
276
def assert_all_input_consumed(self):
334
277
if self.responses:
335
278
raise AssertionError("expected all input in %r to be consumed"
362
305
def show_transport_activity(self, transport, direction, byte_count):
365
def log_transport_activity(self, display=False):
369
class NullOutputStream(object):
370
"""Acts like a file, but discard all output."""
372
def __init__(self, encoding):
373
self.encoding = encoding
375
def write(self, data):
378
def writelines(self, data):