~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Patch Queue Manager
  • Date: 2014-04-09 13:36:25 UTC
  • mfrom: (6592.1.2 1303879-py27-issues)
  • Revision ID: pqm@pqm.ubuntu.com-20140409133625-s24spv3kha2w2860
(vila) Fix python-2.7.6 test failures. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    back to working through the terminal.
42
42
"""
43
43
 
 
44
from __future__ import absolute_import
44
45
 
45
46
import warnings
46
47
 
47
48
from bzrlib.lazy_import import lazy_import
48
49
lazy_import(globals(), """
49
50
from bzrlib import (
 
51
    config,
50
52
    osutils,
51
53
    progress,
52
54
    trace,
145
147
            "This may take some time. Upgrade the repositories to the "
146
148
            "same format for better performance."
147
149
            ),
 
150
        experimental_format_fetch=("Fetching into experimental format "
 
151
            "%(to_format)s.\n"
 
152
            "This format may be unreliable or change in the future "
 
153
            "without an upgrade path.\n"),
148
154
        deprecated_command=(
149
155
            "The command 'bzr %(deprecated_name)s' "
150
156
            "has been deprecated in bzr %(deprecated_in_version)s. "
151
157
            "Please use 'bzr %(recommended_name)s' instead."),
 
158
        deprecated_command_option=(
 
159
            "The option '%(deprecated_name)s' to 'bzr %(command)s' "
 
160
            "has been deprecated in bzr %(deprecated_in_version)s. "
 
161
            "Please use '%(recommended_name)s' instead."),
152
162
        recommend_upgrade=("%(current_format_name)s is deprecated "
153
163
            "and a better format is available.\n"
154
164
            "It is recommended that you upgrade by "
155
165
            "running the command\n"
156
166
            "  bzr upgrade %(basedir)s"),
 
167
        locks_steal_dead=(
 
168
            u"Stole dead lock %(lock_url)s %(other_holder_info)s."),
 
169
        not_checking_ssl_cert=(
 
170
            u"Not checking SSL certificate for %(host)s."),
157
171
        )
158
172
 
159
173
    def __init__(self):
241
255
        """
242
256
        # XXX: is the caller supposed to close the resulting object?
243
257
        if encoding is None:
244
 
            from bzrlib import config
245
 
            encoding = config.GlobalConfig().get_user_option(
246
 
                'output_encoding')
 
258
            encoding = config.GlobalStack().get('output_encoding')
247
259
        if encoding is None:
248
260
            encoding = osutils.get_terminal_encoding(trace=True)
249
261
        if encoding_type is None:
304
316
        try:
305
317
            template = self._user_warning_templates[warning_id]
306
318
        except KeyError:
307
 
            fail = "failed to format warning %r, %r" % (warning_id, message_args)
308
 
            warnings.warn(fail)   # so tests will fail etc
 
319
            fail = "bzr warning: %r, %r" % (warning_id, message_args)
 
320
            warnings.warn("no template for warning: " + fail)   # so tests will fail etc
309
321
            return fail
310
322
        try:
311
323
            return template % message_args
312
324
        except ValueError, e:
313
 
            fail = "failed to format warning %r, %r: %s" % (
 
325
            fail = "bzr unprintable warning: %r, %r, %s" % (
314
326
                warning_id, message_args, e)
315
327
            warnings.warn(fail)   # so tests will fail etc
316
328
            return fail
317
329
 
 
330
    def choose(self, msg, choices, default=None):
 
331
        """Prompt the user for a list of alternatives.
 
332
 
 
333
        :param msg: message to be shown as part of the prompt.
 
334
 
 
335
        :param choices: list of choices, with the individual choices separated
 
336
            by '\n', e.g.: choose("Save changes?", "&Yes\n&No\n&Cancel"). The
 
337
            letter after the '&' is the shortcut key for that choice. Thus you
 
338
            can type 'c' to select "Cancel".  Shorcuts are case insensitive.
 
339
            The shortcut does not need to be the first letter. If a shorcut key
 
340
            is not provided, the first letter for the choice will be used.
 
341
 
 
342
        :param default: default choice (index), returned for example when enter
 
343
            is pressed for the console version.
 
344
 
 
345
        :return: the index fo the user choice (so '0', '1' or '2' for
 
346
            respectively yes/no/cancel in the previous example).
 
347
        """
 
348
        raise NotImplementedError(self.choose)
 
349
 
318
350
    def get_boolean(self, prompt):
319
351
        """Get a boolean question answered from the user.
320
352
 
322
354
            line without terminating \\n.
323
355
        :return: True or False for y/yes or n/no.
324
356
        """
325
 
        raise NotImplementedError(self.get_boolean)
 
357
        choice = self.choose(prompt + '?', '&yes\n&no', default=None)
 
358
        return 0 == choice
326
359
 
327
360
    def get_integer(self, prompt):
328
361
        """Get an integer from the user.
406
439
        """Show a warning to the user."""
407
440
        raise NotImplementedError(self.show_warning)
408
441
 
409
 
    def warn_cross_format_fetch(self, from_format, to_format):
410
 
        """Warn about a potentially slow cross-format transfer.
411
 
        
412
 
        This is deprecated in favor of show_user_warning, but retained for api
413
 
        compatibility in 2.0 and 2.1.
414
 
        """
415
 
        self.show_user_warning('cross_format_fetch', from_format=from_format,
416
 
            to_format=to_format)
417
 
 
418
 
    def warn_experimental_format_fetch(self, inter):
419
 
        """Warn about fetching into experimental repository formats."""
420
 
        if inter.target._format.experimental:
421
 
            trace.warning("Fetching into experimental format %s.\n"
422
 
                "This format may be unreliable or change in the future "
423
 
                "without an upgrade path.\n" % (inter.target._format,))
424
 
 
425
442
 
426
443
class NoninteractiveUIFactory(UIFactory):
427
444
    """Base class for UIs with no user."""