~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2011-02-10 12:37:27 UTC
  • mto: This revision was merged to the branch mainline in revision 5661.
  • Revision ID: v.ladeuil+lp@free.fr-20110210123727-8e0pu4wtlt6fj7nf
thread is already a python module, avoid confusion and use cethread instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 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
42
42
"""
43
43
 
44
44
 
 
45
import os
 
46
import sys
45
47
import warnings
46
48
 
47
49
from bzrlib.lazy_import import lazy_import
48
50
lazy_import(globals(), """
 
51
import getpass
 
52
 
49
53
from bzrlib import (
50
 
    config,
 
54
    errors,
51
55
    osutils,
52
56
    progress,
53
57
    trace,
54
58
    )
55
59
""")
 
60
from bzrlib.symbol_versioning import (
 
61
    deprecated_function,
 
62
    deprecated_in,
 
63
    deprecated_method,
 
64
    )
56
65
 
57
66
 
58
67
_valid_boolean_strings = dict(yes=True, no=False,
145
154
            "%(from_format)s to %(to_format)s.\n"
146
155
            "This may take some time. Upgrade the repositories to the "
147
156
            "same format for better performance."
148
 
            ),
149
 
        experimental_format_fetch=("Fetching into experimental format "
150
 
            "%(to_format)s.\n"
151
 
            "This format may be unreliable or change in the future "
152
 
            "without an upgrade path.\n"),
153
 
        deprecated_command=(
154
 
            "The command 'bzr %(deprecated_name)s' "
155
 
            "has been deprecated in bzr %(deprecated_in_version)s. "
156
 
            "Please use 'bzr %(recommended_name)s' instead."),
157
 
        deprecated_command_option=(
158
 
            "The option '%(deprecated_name)s' to 'bzr %(command)s' "
159
 
            "has been deprecated in bzr %(deprecated_in_version)s. "
160
 
            "Please use '%(recommended_name)s' instead."),
161
 
        recommend_upgrade=("%(current_format_name)s is deprecated "
162
 
            "and a better format is available.\n"
163
 
            "It is recommended that you upgrade by "
164
 
            "running the command\n"
165
 
            "  bzr upgrade %(basedir)s"),
166
 
        locks_steal_dead=(
167
 
            u"Stole dead lock %(lock_url)s %(other_holder_info)s."),
 
157
            )
168
158
        )
169
159
 
170
160
    def __init__(self):
215
205
        """
216
206
        return self.get_boolean(prompt % prompt_kwargs)
217
207
 
218
 
    def get_password(self, prompt=u'', **kwargs):
 
208
    def get_password(self, prompt='', **kwargs):
219
209
        """Prompt the user for a password.
220
210
 
221
 
        :param prompt: The prompt to present the user (must be unicode)
 
211
        :param prompt: The prompt to present the user
222
212
        :param kwargs: Arguments which will be expanded into the prompt.
223
213
                       This lets front ends display different things if
224
214
                       they so choose.
252
242
        """
253
243
        # XXX: is the caller supposed to close the resulting object?
254
244
        if encoding is None:
255
 
            encoding = config.GlobalStack().get('output_encoding')
 
245
            from bzrlib import config
 
246
            encoding = config.GlobalConfig().get_user_option(
 
247
                'output_encoding')
256
248
        if encoding is None:
257
249
            encoding = osutils.get_terminal_encoding(trace=True)
258
250
        if encoding_type is None:
313
305
        try:
314
306
            template = self._user_warning_templates[warning_id]
315
307
        except KeyError:
316
 
            fail = "bzr warning: %r, %r" % (warning_id, message_args)
317
 
            warnings.warn("no template for warning: " + fail)   # so tests will fail etc
 
308
            fail = "failed to format warning %r, %r" % (warning_id, message_args)
 
309
            warnings.warn(fail)   # so tests will fail etc
318
310
            return fail
319
311
        try:
320
312
            return template % message_args
321
313
        except ValueError, e:
322
 
            fail = "bzr unprintable warning: %r, %r, %s" % (
 
314
            fail = "failed to format warning %r, %r: %s" % (
323
315
                warning_id, message_args, e)
324
316
            warnings.warn(fail)   # so tests will fail etc
325
317
            return fail
328
320
        """Get a boolean question answered from the user.
329
321
 
330
322
        :param prompt: a message to prompt the user with. Should be a single
331
 
            line without terminating \\n.
 
323
        line without terminating \n.
332
324
        :return: True or False for y/yes or n/no.
333
325
        """
334
326
        raise NotImplementedError(self.get_boolean)
337
329
        """Get an integer from the user.
338
330
 
339
331
        :param prompt: a message to prompt the user with. Could be a multi-line
340
 
            prompt but without a terminating \\n.
 
332
            prompt but without a terminating \n.
341
333
 
342
334
        :return: A signed integer.
343
335
        """
351
343
        """
352
344
        return NullProgressView()
353
345
 
354
 
    def recommend_upgrade(self, current_format_name, basedir):
355
 
        """Recommend the user upgrade a control directory.
356
 
 
357
 
        :param current_format_name: Description of the current format
358
 
        :param basedir: Location of the control dir
359
 
        """
360
 
        self.show_user_warning('recommend_upgrade',
361
 
            current_format_name=current_format_name, basedir=basedir)
 
346
    def recommend_upgrade(self,
 
347
        current_format_name,
 
348
        basedir):
 
349
        # XXX: this should perhaps be in the TextUIFactory and the default can do
 
350
        # nothing
 
351
        #
 
352
        # XXX: Change to show_user_warning - that will accomplish the previous
 
353
        # xxx. -- mbp 2010-02-25
 
354
        trace.warning("%s is deprecated "
 
355
            "and a better format is available.\n"
 
356
            "It is recommended that you upgrade by "
 
357
            "running the command\n"
 
358
            "  bzr upgrade %s",
 
359
            current_format_name,
 
360
            basedir)
362
361
 
363
362
    def report_transport_activity(self, transport, byte_count, direction):
364
363
        """Called by transports as they do IO.
415
414
        """Show a warning to the user."""
416
415
        raise NotImplementedError(self.show_warning)
417
416
 
 
417
    def warn_cross_format_fetch(self, from_format, to_format):
 
418
        """Warn about a potentially slow cross-format transfer.
 
419
        
 
420
        This is deprecated in favor of show_user_warning, but retained for api
 
421
        compatibility in 2.0 and 2.1.
 
422
        """
 
423
        self.show_user_warning('cross_format_fetch', from_format=from_format,
 
424
            to_format=to_format)
 
425
 
 
426
    def warn_experimental_format_fetch(self, inter):
 
427
        """Warn about fetching into experimental repository formats."""
 
428
        if inter.target._format.experimental:
 
429
            trace.warning("Fetching into experimental format %s.\n"
 
430
                "This format may be unreliable or change in the future "
 
431
                "without an upgrade path.\n" % (inter.target._format,))
 
432
 
418
433
 
419
434
class NoninteractiveUIFactory(UIFactory):
420
435
    """Base class for UIs with no user."""
476
491
    def get_integer(self, prompt):
477
492
        return self.responses.pop(0)
478
493
 
479
 
    def get_password(self, prompt=u'', **kwargs):
 
494
    def get_password(self, prompt='', **kwargs):
480
495
        return self.responses.pop(0)
481
496
 
482
497
    def get_username(self, prompt, **kwargs):