~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2007-03-26 06:24:01 UTC
  • mto: This revision was merged to the branch mainline in revision 2376.
  • Revision ID: andrew.bennetts@canonical.com-20070326062401-k3nbefzje5332jaf
Deal with review comments from Robert:

  * Add my name to the NEWS file
  * Move the test case to a new module in branch_implementations
  * Remove revision_history cruft from identitymap and test_identitymap
  * Improve some docstrings

Also, this fixes a bug where revision_history was not returning a copy of the
cached data, allowing the cache to be corrupted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
 
 
18
 
17
19
"""UI abstraction.
18
20
 
19
21
This tells the library how to display things to the user.  Through this
33
35
import getpass
34
36
 
35
37
from bzrlib import (
36
 
    errors,
37
 
    osutils,
38
38
    progress,
39
 
    trace,
40
39
    )
41
40
""")
42
41
 
 
42
from bzrlib.symbol_versioning import (deprecated_method, zero_eight)
 
43
 
43
44
 
44
45
class UIFactory(object):
45
46
    """UI abstraction.
52
53
        super(UIFactory, self).__init__()
53
54
        self._progress_bar_stack = None
54
55
 
 
56
    @deprecated_method(zero_eight)
 
57
    def progress_bar(self):
 
58
        """See UIFactory.nested_progress_bar()."""
 
59
        raise NotImplementedError(self.progress_bar)
 
60
 
55
61
    def get_password(self, prompt='', **kwargs):
56
62
        """Prompt the user for a password.
57
63
 
91
97
        """
92
98
        raise NotImplementedError(self.get_boolean)
93
99
 
94
 
    def recommend_upgrade(self,
95
 
        current_format_name,
96
 
        basedir):
97
 
        # this should perhaps be in the TextUIFactory and the default can do
98
 
        # nothing
99
 
        trace.warning("%s is deprecated "
100
 
            "and a better format is available.\n"
101
 
            "It is recommended that you upgrade by "
102
 
            "running the command\n"
103
 
            "  bzr upgrade %s",
104
 
            current_format_name,
105
 
            basedir)
106
 
 
107
100
 
108
101
class CLIUIFactory(UIFactory):
109
102
    """Common behaviour for command line UI factories."""
124
117
                return False
125
118
 
126
119
    def get_non_echoed_password(self, prompt):
127
 
        if not sys.stdin.isatty():
128
 
            raise errors.NotATerminal()
129
 
        encoding = osutils.get_terminal_encoding()
130
 
        return getpass.getpass(prompt.encode(encoding, 'replace'))
 
120
        return getpass.getpass(prompt)
131
121
 
132
122
    def get_password(self, prompt='', **kwargs):
133
123
        """Prompt the user for a password.
140
130
                 canceled the request.
141
131
        """
142
132
        prompt += ': '
143
 
        prompt = (prompt % kwargs)
 
133
        prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
144
134
        # There's currently no way to say 'i decline to enter a password'
145
135
        # as opposed to 'my password is empty' -- does it matter?
146
136
        return self.get_non_echoed_password(prompt)
155
145
    This is the default UI, if another one is never registered.
156
146
    """
157
147
 
 
148
    @deprecated_method(zero_eight)
 
149
    def progress_bar(self):
 
150
        """See UIFactory.nested_progress_bar()."""
 
151
        return progress.DummyProgress()
 
152
 
158
153
    def get_password(self, prompt='', **kwargs):
159
154
        return None
160
155
 
167
162
    def clear_term(self):
168
163
        pass
169
164
 
170
 
    def recommend_upgrade(self, *args):
171
 
        pass
172
 
 
173
165
 
174
166
def clear_decorator(func, *args, **kwargs):
175
167
    """Decorator that clears the term"""