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

  • Committer: Alexander Belchenko
  • Date: 2007-03-13 02:16:17 UTC
  • mfrom: (2346 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2356.
  • Revision ID: bialix@ukr.net-20070313021617-azd5lv30b23gyu48
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
from bzrlib.lazy_import import lazy_import
34
34
lazy_import(globals(), """
 
35
import getpass
 
36
 
35
37
from bzrlib import (
36
38
    progress,
37
39
    )
63
65
        :param kwargs: Arguments which will be expanded into the prompt.
64
66
                       This lets front ends display different things if
65
67
                       they so choose.
66
 
        :return: The password string, return None if the user 
67
 
                 canceled the request.
 
68
 
 
69
        :return: The password string, return None if the user canceled the
 
70
                 request. Note that we do not touch the encoding, users may
 
71
                 have whatever they see fit and the password should be
 
72
                 transported as is.
68
73
        """
69
74
        raise NotImplementedError(self.get_password)
70
 
        
 
75
 
71
76
    def nested_progress_bar(self):
72
77
        """Return a nested progress bar.
73
78
 
104
109
        self.clear_term()
105
110
        # FIXME: make a regexp and handle case variations as well.
106
111
        while True:
107
 
            self.prompt(prompt)
 
112
            self.prompt(prompt + "? [y/n]: ")
108
113
            line = self.stdin.readline()
109
114
            if line in ('y\n', 'yes\n'):
110
115
                return True
111
116
            if line in ('n\n', 'no\n'):
112
117
                return False
113
118
 
 
119
    def get_non_echoed_password(self, prompt):
 
120
        return getpass.getpass(prompt)
 
121
 
 
122
    def get_password(self, prompt='', **kwargs):
 
123
        """Prompt the user for a password.
 
124
 
 
125
        :param prompt: The prompt to present the user
 
126
        :param kwargs: Arguments which will be expanded into the prompt.
 
127
                       This lets front ends display different things if
 
128
                       they so choose.
 
129
        :return: The password string, return None if the user 
 
130
                 canceled the request.
 
131
        """
 
132
        prompt += ': '
 
133
        prompt = (prompt % kwargs).encode(sys.stdout.encoding, 'replace')
 
134
        # There's currently no way to say 'i decline to enter a password'
 
135
        # as opposed to 'my password is empty' -- does it matter?
 
136
        return self.get_non_echoed_password(prompt)
 
137
 
114
138
    def prompt(self, prompt):
115
139
        """Emit prompt on the CLI."""
116
140