151
151
mail_client_class = {
152
152
None: mail_client.DefaultMail,
153
153
# Specific clients
154
'emacsclient': mail_client.EmacsMail,
154
155
'evolution': mail_client.Evolution,
155
156
'kmail': mail_client.KMail,
156
157
'mutt': mail_client.Mutt,
891
892
"""Branch configuration data associated with its contents, not location"""
893
894
def __init__(self, branch):
895
transport = branch.control_files._transport
896
self._config = TransportConfig(transport, 'branch.conf')
894
897
self.branch = branch
896
899
def _get_parser(self, file=None):
897
900
if file is not None:
898
901
return IniBasedConfig._get_parser(file)
899
return self._get_config()
901
def _get_config(self):
903
obj = ConfigObj(self.branch.control_files.get('branch.conf'),
905
except errors.NoSuchFile:
906
obj = ConfigObj(encoding='utf=8')
902
return self._config._get_configobj()
909
904
def get_option(self, name, section=None, default=None):
910
905
self.branch.lock_read()
912
obj = self._get_config()
914
if section is not None:
907
return self._config.get_option(name, section, default)
920
909
self.branch.unlock()
924
913
"""Set a per-branch configuration option"""
925
914
self.branch.lock_write()
927
cfg_obj = self._get_config()
932
obj = cfg_obj[section]
934
cfg_obj[section] = {}
935
obj = cfg_obj[section]
937
out_file = StringIO()
938
cfg_obj.write(out_file)
940
self.branch.control_files.put('branch.conf', out_file)
916
self._config.set_option(value, name, section)
942
918
self.branch.unlock()
1126
1102
def decode_password(self, credentials, encoding):
1127
1103
return credentials
1106
class TransportConfig(object):
1107
"""A Config that reads/writes a config file on a Transport.
1109
It is a low-level object that considers config data to be name/value pairs
1110
that may be associated with a section. Assigning meaning to the these
1111
values is done at higher levels like TreeConfig.
1114
def __init__(self, transport, filename):
1115
self._transport = transport
1116
self._filename = filename
1118
def get_option(self, name, section=None, default=None):
1119
"""Return the value associated with a named option.
1121
:param name: The name of the value
1122
:param section: The section the option is in (if any)
1123
:param default: The value to return if the value is not set
1124
:return: The value or default value
1126
configobj = self._get_configobj()
1128
section_obj = configobj
1131
section_obj = configobj[section]
1134
return section_obj.get(name, default)
1136
def set_option(self, value, name, section=None):
1137
"""Set the value associated with a named option.
1139
:param value: The value to set
1140
:param name: The name of the value to set
1141
:param section: The section the option is in (if any)
1143
configobj = self._get_configobj()
1145
configobj[name] = value
1147
configobj.setdefault(section, {})[name] = value
1148
self._set_configobj(configobj)
1150
def _get_configobj(self):
1152
return ConfigObj(self._transport.get(self._filename),
1154
except errors.NoSuchFile:
1155
return ConfigObj(encoding='utf-8')
1157
def _set_configobj(self, configobj):
1158
out_file = StringIO()
1159
configobj.write(out_file)
1161
self._transport.put_file(self._filename, out_file)