~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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 "
156
166
            "  bzr upgrade %(basedir)s"),
157
167
        locks_steal_dead=(
158
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."),
159
171
        )
160
172
 
161
173
    def __init__(self):
243
255
        """
244
256
        # XXX: is the caller supposed to close the resulting object?
245
257
        if encoding is None:
246
 
            from bzrlib import config
247
 
            encoding = config.GlobalConfig().get_user_option(
248
 
                'output_encoding')
 
258
            encoding = config.GlobalStack().get('output_encoding')
249
259
        if encoding is None:
250
260
            encoding = osutils.get_terminal_encoding(trace=True)
251
261
        if encoding_type is None:
317
327
            warnings.warn(fail)   # so tests will fail etc
318
328
            return fail
319
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
 
320
350
    def get_boolean(self, prompt):
321
351
        """Get a boolean question answered from the user.
322
352
 
324
354
            line without terminating \\n.
325
355
        :return: True or False for y/yes or n/no.
326
356
        """
327
 
        raise NotImplementedError(self.get_boolean)
 
357
        choice = self.choose(prompt + '?', '&yes\n&no', default=None)
 
358
        return 0 == choice
328
359
 
329
360
    def get_integer(self, prompt):
330
361
        """Get an integer from the user.
408
439
        """Show a warning to the user."""
409
440
        raise NotImplementedError(self.show_warning)
410
441
 
411
 
    def warn_cross_format_fetch(self, from_format, to_format):
412
 
        """Warn about a potentially slow cross-format transfer.
413
 
        
414
 
        This is deprecated in favor of show_user_warning, but retained for api
415
 
        compatibility in 2.0 and 2.1.
416
 
        """
417
 
        self.show_user_warning('cross_format_fetch', from_format=from_format,
418
 
            to_format=to_format)
419
 
 
420
 
    def warn_experimental_format_fetch(self, inter):
421
 
        """Warn about fetching into experimental repository formats."""
422
 
        if inter.target._format.experimental:
423
 
            trace.warning("Fetching into experimental format %s.\n"
424
 
                "This format may be unreliable or change in the future "
425
 
                "without an upgrade path.\n" % (inter.target._format,))
426
 
 
427
442
 
428
443
class NoninteractiveUIFactory(UIFactory):
429
444
    """Base class for UIs with no user."""