~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

(jameinel) Allow 'bzr serve' to interpret SIGHUP as a graceful shutdown.
 (bug #795025) (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
47
45
import warnings
48
46
 
49
47
from bzrlib.lazy_import import lazy_import
50
48
lazy_import(globals(), """
51
 
import getpass
52
 
 
53
49
from bzrlib import (
54
 
    errors,
 
50
    config,
55
51
    osutils,
56
52
    progress,
57
53
    trace,
58
54
    )
59
55
""")
60
 
from bzrlib.symbol_versioning import (
61
 
    deprecated_function,
62
 
    deprecated_in,
63
 
    deprecated_method,
64
 
    )
65
56
 
66
57
 
67
58
_valid_boolean_strings = dict(yes=True, no=False,
154
145
            "%(from_format)s to %(to_format)s.\n"
155
146
            "This may take some time. Upgrade the repositories to the "
156
147
            "same format for better performance."
157
 
            )
 
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."),
158
168
        )
159
169
 
160
170
    def __init__(self):
205
215
        """
206
216
        return self.get_boolean(prompt % prompt_kwargs)
207
217
 
208
 
    def get_password(self, prompt='', **kwargs):
 
218
    def get_password(self, prompt=u'', **kwargs):
209
219
        """Prompt the user for a password.
210
220
 
211
 
        :param prompt: The prompt to present the user
 
221
        :param prompt: The prompt to present the user (must be unicode)
212
222
        :param kwargs: Arguments which will be expanded into the prompt.
213
223
                       This lets front ends display different things if
214
224
                       they so choose.
242
252
        """
243
253
        # XXX: is the caller supposed to close the resulting object?
244
254
        if encoding is None:
245
 
            from bzrlib import config
246
 
            encoding = config.GlobalConfig().get_user_option(
247
 
                'output_encoding')
 
255
            encoding = config.GlobalStack().get('output_encoding')
248
256
        if encoding is None:
249
257
            encoding = osutils.get_terminal_encoding(trace=True)
250
258
        if encoding_type is None:
305
313
        try:
306
314
            template = self._user_warning_templates[warning_id]
307
315
        except KeyError:
308
 
            fail = "failed to format warning %r, %r" % (warning_id, message_args)
309
 
            warnings.warn(fail)   # so tests will fail etc
 
316
            fail = "bzr warning: %r, %r" % (warning_id, message_args)
 
317
            warnings.warn("no template for warning: " + fail)   # so tests will fail etc
310
318
            return fail
311
319
        try:
312
320
            return template % message_args
313
321
        except ValueError, e:
314
 
            fail = "failed to format warning %r, %r: %s" % (
 
322
            fail = "bzr unprintable warning: %r, %r, %s" % (
315
323
                warning_id, message_args, e)
316
324
            warnings.warn(fail)   # so tests will fail etc
317
325
            return fail
320
328
        """Get a boolean question answered from the user.
321
329
 
322
330
        :param prompt: a message to prompt the user with. Should be a single
323
 
        line without terminating \n.
 
331
            line without terminating \\n.
324
332
        :return: True or False for y/yes or n/no.
325
333
        """
326
334
        raise NotImplementedError(self.get_boolean)
329
337
        """Get an integer from the user.
330
338
 
331
339
        :param prompt: a message to prompt the user with. Could be a multi-line
332
 
            prompt but without a terminating \n.
 
340
            prompt but without a terminating \\n.
333
341
 
334
342
        :return: A signed integer.
335
343
        """
343
351
        """
344
352
        return NullProgressView()
345
353
 
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)
 
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)
361
362
 
362
363
    def report_transport_activity(self, transport, byte_count, direction):
363
364
        """Called by transports as they do IO.
414
415
        """Show a warning to the user."""
415
416
        raise NotImplementedError(self.show_warning)
416
417
 
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
 
 
433
418
 
434
419
class NoninteractiveUIFactory(UIFactory):
435
420
    """Base class for UIs with no user."""
491
476
    def get_integer(self, prompt):
492
477
        return self.responses.pop(0)
493
478
 
494
 
    def get_password(self, prompt='', **kwargs):
 
479
    def get_password(self, prompt=u'', **kwargs):
495
480
        return self.responses.pop(0)
496
481
 
497
482
    def get_username(self, prompt, **kwargs):