/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

Merge description into dont-add-conflict-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
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
109
109
 
110
110
    def __init__(self):
111
111
        self._task_stack = []
 
112
        self._quiet = False
 
113
 
 
114
    def be_quiet(self, state):
 
115
        """Tell the UI to be more quiet, or not.
 
116
 
 
117
        Typically this suppresses progress bars; the application may also look
 
118
        at ui_factory.is_quiet().
 
119
        """
 
120
        self._quiet = state
112
121
 
113
122
    def get_password(self, prompt='', **kwargs):
114
123
        """Prompt the user for a password.
125
134
        """
126
135
        raise NotImplementedError(self.get_password)
127
136
 
 
137
    def is_quiet(self):
 
138
        return self._quiet
 
139
 
128
140
    def make_output_stream(self, encoding=None, encoding_type=None):
129
141
        """Get a stream for sending out bulk text data.
130
142
 
246
258
        """
247
259
        pass
248
260
 
 
261
    def log_transport_activity(self, display=False):
 
262
        """Write out whatever transport activity has been measured.
 
263
 
 
264
        Implementations are allowed to do nothing, but it is useful if they can
 
265
        write a line to the log file.
 
266
 
 
267
        :param display: If False, only log to disk, if True also try to display
 
268
            a message to the user.
 
269
        :return: None
 
270
        """
 
271
        # Default implementation just does nothing
 
272
        pass
 
273
 
249
274
    def show_error(self, msg):
250
275
        """Show an error message (not an exception) to the user.
251
276
        
252
277
        The message should not have an error prefix or trailing newline.  That
253
 
        will be added by the factory if appropriate. 
 
278
        will be added by the factory if appropriate.
254
279
        """
255
280
        raise NotImplementedError(self.show_error)
256
281
 
262
287
        """Show a warning to the user."""
263
288
        raise NotImplementedError(self.show_warning)
264
289
 
 
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))
265
297
 
266
298
 
267
299
class SilentUIFactory(UIFactory):
283
315
    def get_username(self, prompt, **kwargs):
284
316
        return None
285
317
 
 
318
    def _make_output_stream_explicit(self, encoding, encoding_type):
 
319
        return NullOutputStream(encoding)
 
320
 
286
321
    def show_error(self, msg):
287
322
        pass
288
323
 
345
380
 
346
381
    def show_transport_activity(self, transport, direction, byte_count):
347
382
        pass
 
383
 
 
384
    def log_transport_activity(self, display=False):
 
385
        pass
 
386
 
 
387
 
 
388
class NullOutputStream(object):
 
389
    """Acts like a file, but discard all output."""
 
390
 
 
391
    def __init__(self, encoding):
 
392
        self.encoding = encoding
 
393
 
 
394
    def write(self, data):
 
395
        pass
 
396
 
 
397
    def writelines(self, data):
 
398
        pass
 
399
 
 
400
    def close(self):
 
401
        pass