/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/config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-04-10 19:37:20 UTC
  • mfrom: (4222.3.15 username)
  • Revision ID: pqm@pqm.ubuntu.com-20090410193720-nyej7ft1k2yoyhui
(Jelmer) Prompt for user names for http if they are not in the
        configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1126
1126
        config.update({name: values})
1127
1127
        self._save()
1128
1128
 
1129
 
    def get_user(self, scheme, host, port=None,
1130
 
                 realm=None, path=None, prompt=None):
 
1129
    def get_user(self, scheme, host, port=None, realm=None, path=None, 
 
1130
                 prompt=None, ask=False, default=None):
1131
1131
        """Get a user from authentication file.
1132
1132
 
1133
1133
        :param scheme: protocol
1140
1140
 
1141
1141
        :param path: the absolute path on the server (optional)
1142
1142
 
 
1143
        :param ask: Ask the user if there is no explicitly configured username 
 
1144
                    (optional)
 
1145
 
1143
1146
        :return: The found user.
1144
1147
        """
1145
1148
        credentials = self.get_credentials(scheme, host, port, user=None,
1148
1151
            user = credentials['user']
1149
1152
        else:
1150
1153
            user = None
 
1154
        if user is None:
 
1155
            if ask:
 
1156
                if prompt is None:
 
1157
                    # Create a default prompt suitable for most cases
 
1158
                    prompt = scheme.upper() + ' %(host)s username'
 
1159
                # Special handling for optional fields in the prompt
 
1160
                if port is not None:
 
1161
                    prompt_host = '%s:%d' % (host, port)
 
1162
                else:
 
1163
                    prompt_host = host
 
1164
                user = ui.ui_factory.get_username(prompt, host=prompt_host)
 
1165
            else:
 
1166
                if default is None:
 
1167
                    import getpass
 
1168
                    default = getpass.getuser()
 
1169
                user = default
1151
1170
        return user
1152
1171
 
1153
1172
    def get_password(self, scheme, host, user, port=None,