/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 breezy/ui/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

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
 
45
 
44
46
import warnings
45
47
 
46
48
from ..lazy_import import lazy_import
52
54
    )
53
55
""")
54
56
 
 
57
from ..sixish import (
 
58
    PY3,
 
59
    string_types,
 
60
    text_type,
 
61
    )
 
62
 
55
63
 
56
64
_valid_boolean_strings = dict(yes=True, no=False,
57
65
                              y=True, n=False,
81
89
    if accepted_values is None:
82
90
        accepted_values = _valid_boolean_strings
83
91
    val = None
84
 
    if isinstance(s, str):
 
92
    if isinstance(s, string_types):
85
93
        try:
86
94
            val = accepted_values[s.lower()]
87
95
        except KeyError:
140
148
 
141
149
    _user_warning_templates = dict(
142
150
        cross_format_fetch=("Doing on-the-fly conversion from "
143
 
                            "%(from_format)s to %(to_format)s.\n"
144
 
                            "This may take some time. Upgrade the repositories to the "
145
 
                            "same format for better performance."
146
 
                            ),
 
151
            "%(from_format)s to %(to_format)s.\n"
 
152
            "This may take some time. Upgrade the repositories to the "
 
153
            "same format for better performance."
 
154
            ),
147
155
        experimental_format_fetch=("Fetching into experimental format "
148
 
                                   "%(to_format)s.\n"
149
 
                                   "This format may be unreliable or change in the future "
150
 
                                   "without an upgrade path.\n"),
 
156
            "%(to_format)s.\n"
 
157
            "This format may be unreliable or change in the future "
 
158
            "without an upgrade path.\n"),
151
159
        deprecated_command=(
152
160
            "The command 'brz %(deprecated_name)s' "
153
161
            "has been deprecated in brz %(deprecated_in_version)s. "
157
165
            "has been deprecated in brz %(deprecated_in_version)s. "
158
166
            "Please use '%(recommended_name)s' instead."),
159
167
        recommend_upgrade=("%(current_format_name)s is deprecated "
160
 
                           "and a better format is available.\n"
161
 
                           "It is recommended that you upgrade by "
162
 
                           "running the command\n"
163
 
                           "  brz upgrade %(basedir)s"),
 
168
            "and a better format is available.\n"
 
169
            "It is recommended that you upgrade by "
 
170
            "running the command\n"
 
171
            "  brz upgrade %(basedir)s"),
164
172
        locks_steal_dead=(
165
173
            u"Stole dead lock %(lock_url)s %(other_holder_info)s."),
166
174
        not_checking_ssl_cert=(
178
186
        Override in a concrete factory class if initialisation before use is
179
187
        needed.
180
188
        """
181
 
        return self  # This is bound to the 'as' clause in a with statement.
 
189
        return self # This is bound to the 'as' clause in a with statement.
182
190
 
183
191
    def __exit__(self, exc_type, exc_val, exc_tb):
184
192
        """Context manager exit support.
187
195
        self.clear_term() is needed when the UIFactory is finished with.
188
196
        """
189
197
        self.clear_term()
190
 
        return False  # propogate exceptions.
 
198
        return False # propogate exceptions.
191
199
 
192
200
    def be_quiet(self, state):
193
201
        """Tell the UI to be more quiet, or not.
257
265
 
258
266
    def _make_output_stream_explicit(self, encoding, encoding_type):
259
267
        raise NotImplementedError("%s doesn't support make_output_stream"
260
 
                                  % (self.__class__.__name__))
 
268
            % (self.__class__.__name__))
261
269
 
262
270
    def nested_progress_bar(self):
263
271
        """Return a nested progress bar.
276
284
        """Called by the ProgressTask when it finishes"""
277
285
        if not self._task_stack:
278
286
            warnings.warn("%r finished but nothing is active"
279
 
                          % (task,))
 
287
                % (task,))
280
288
        if task in self._task_stack:
281
289
            self._task_stack.remove(task)
282
290
        else:
283
291
            warnings.warn("%r is not in active stack %r"
284
 
                          % (task, self._task_stack))
 
292
                % (task, self._task_stack))
285
293
        if not self._task_stack:
286
294
            self._progress_all_finished()
287
295
 
309
317
            template = self._user_warning_templates[warning_id]
310
318
        except KeyError:
311
319
            fail = "brz warning: %r, %r" % (warning_id, message_args)
312
 
            warnings.warn("no template for warning: "
313
 
                          + fail)   # so tests will fail etc
314
 
            return str(fail)
 
320
            warnings.warn("no template for warning: " + fail)   # so tests will fail etc
 
321
            return text_type(fail)
315
322
        try:
316
 
            return str(template) % message_args
 
323
            return text_type(template) % message_args
317
324
        except ValueError as e:
318
325
            fail = "brz unprintable warning: %r, %r, %s" % (
319
326
                warning_id, message_args, e)
320
327
            warnings.warn(fail)   # so tests will fail etc
321
 
            return str(fail)
 
328
            return text_type(fail)
322
329
 
323
330
    def choose(self, msg, choices, default=None):
324
331
        """Prompt the user for a list of alternatives.
375
382
        :param basedir: Location of the control dir
376
383
        """
377
384
        self.show_user_warning('recommend_upgrade',
378
 
                               current_format_name=current_format_name, basedir=basedir)
 
385
            current_format_name=current_format_name, basedir=basedir)
379
386
 
380
387
    def report_transport_activity(self, transport, byte_count, direction):
381
388
        """Called by transports as they do IO.
502
509
    def assert_all_input_consumed(self):
503
510
        if self.responses:
504
511
            raise AssertionError("expected all input in %r to be consumed"
505
 
                                 % (self,))
 
512
                % (self,))
506
513
 
507
514
 
508
515
ui_factory = SilentUIFactory()
515
522
    """
516
523
    # this is now always TextUIFactory, which in turn decides whether it
517
524
    # should display progress bars etc
518
 
    from .text import TextUIFactory
 
525
    from .text import TextUIFactory, _wrap_in_stream, _wrap_out_stream
 
526
    # GZ 2017-05-21: May want to rewrap streams on Python 3 if encoding config
 
527
    if not PY3:
 
528
        stdin = _wrap_in_stream(stdin)
 
529
        stdout = _wrap_out_stream(stdout)
 
530
        stderr = _wrap_out_stream(stderr)
519
531
    return TextUIFactory(stdin, stdout, stderr)
520
532
 
521
533