126
def ConfigObj(*args, **kwargs):
128
if _ConfigObj is None:
129
class ConfigObj(configobj.ConfigObj):
131
def get_bool(self, section, key):
132
return self[section].as_bool(key)
134
def get_value(self, section, name):
135
# Try [] for the old DEFAULT section.
136
if section == "DEFAULT":
141
return self[section][name]
142
_ConfigObj = ConfigObj
143
return _ConfigObj(*args, **kwargs)
125
class ConfigObj(configobj.ConfigObj):
127
def get_bool(self, section, key):
128
return self[section].as_bool(key)
130
def get_value(self, section, name):
131
# Try [] for the old DEFAULT section.
132
if section == "DEFAULT":
137
return self[section][name]
146
140
class Config(object):
153
147
def get_mail_client(self):
154
148
"""Get a mail client to use"""
155
149
selected_client = self.get_user_option('mail_client')
156
_registry = mail_client.mail_client_registry
158
mail_client_class = _registry.get(selected_client)
151
mail_client_class = {
152
None: mail_client.DefaultMail,
154
'emacsclient': mail_client.EmacsMail,
155
'evolution': mail_client.Evolution,
156
'kmail': mail_client.KMail,
157
'mutt': mail_client.Mutt,
158
'thunderbird': mail_client.Thunderbird,
160
'default': mail_client.DefaultMail,
161
'editor': mail_client.Editor,
162
'mapi': mail_client.MAPIClient,
163
'xdg-email': mail_client.XDGEmail,
160
166
raise errors.UnknownMailClient(selected_client)
161
167
return mail_client_class(self)
1070
1071
return credentials
1072
def set_credentials(self, name, host, user, scheme=None, password=None,
1073
port=None, path=None, verify_certificates=None):
1074
"""Set authentication credentials for a host.
1076
Any existing credentials with matching scheme, host, port and path
1077
will be deleted, regardless of name.
1079
:param name: An arbitrary name to describe this set of credentials.
1080
:param host: Name of the host that accepts these credentials.
1081
:param user: The username portion of these credentials.
1082
:param scheme: The URL scheme (e.g. ssh, http) the credentials apply
1084
:param password: Password portion of these credentials.
1085
:param port: The IP port on the host that these credentials apply to.
1086
:param path: A filesystem path on the host that these credentials
1088
:param verify_certificates: On https, verify server certificates if
1091
values = {'host': host, 'user': user}
1092
if password is not None:
1093
values['password'] = password
1094
if scheme is not None:
1095
values['scheme'] = scheme
1096
if port is not None:
1097
values['port'] = '%d' % port
1098
if path is not None:
1099
values['path'] = path
1100
if verify_certificates is not None:
1101
values['verify_certificates'] = str(verify_certificates)
1102
config = self._get_config()
1104
for section, existing_values in config.items():
1105
for key in ('scheme', 'host', 'port', 'path'):
1106
if existing_values.get(key) != values.get(key):
1110
config.update({name: values})
1113
1073
def get_user(self, scheme, host, port=None,
1114
1074
realm=None, path=None, prompt=None):
1115
1075
"""Get a user from authentication file.
1177
1137
return password
1179
1139
def decode_password(self, credentials, encoding):
1181
cs = credential_store_registry.get_credential_store(encoding)
1183
raise ValueError('%r is not a known password_encoding' % encoding)
1184
credentials['password'] = cs.decode_password(credentials)
1185
1140
return credentials
1188
class CredentialStoreRegistry(registry.Registry):
1189
"""A class that registers credential stores.
1191
A credential store provides access to credentials via the password_encoding
1192
field in authentication.conf sections.
1194
Except for stores provided by bzr itself,most stores are expected to be
1195
provided by plugins that will therefore use
1196
register_lazy(password_encoding, module_name, member_name, help=help,
1197
info=info) to install themselves.
1200
def get_credential_store(self, encoding=None):
1201
cs = self.get(encoding)
1207
credential_store_registry = CredentialStoreRegistry()
1210
class CredentialStore(object):
1211
"""An abstract class to implement storage for credentials"""
1213
def decode_password(self, credentials):
1214
"""Returns a password for the provided credentials in clear text."""
1215
raise NotImplementedError(self.decode_password)
1218
class PlainTextCredentialStore(CredentialStore):
1219
"""Plain text credential store for the authentication.conf file."""
1221
def decode_password(self, credentials):
1222
"""See CredentialStore.decode_password."""
1223
return credentials['password']
1226
credential_store_registry.register('plain', PlainTextCredentialStore,
1227
help=PlainTextCredentialStore.__doc__)
1228
credential_store_registry.default_key = 'plain'
1231
class BzrDirConfig(object):
1233
def __init__(self, transport):
1234
self._config = TransportConfig(transport, 'control.conf')
1236
def set_default_stack_on(self, value):
1237
"""Set the default stacking location.
1239
It may be set to a location, or None.
1241
This policy affects all branches contained by this bzrdir, except for
1242
those under repositories.
1245
self._config.set_option('', 'default_stack_on')
1247
self._config.set_option(value, 'default_stack_on')
1249
def get_default_stack_on(self):
1250
"""Return the default stacking location.
1252
This will either be a location, or None.
1254
This policy affects all branches contained by this bzrdir, except for
1255
those under repositories.
1257
value = self._config.get_option('default_stack_on')
1263
1143
class TransportConfig(object):
1264
1144
"""A Config that reads/writes a config file on a Transport.