137
137
"""A configuration policy that draws from ini files."""
139
139
def _get_parser(self, file=None):
140
if self._parser is not None:
142
parser = ConfigParser()
141
input = self._get_filename()
146
parser.read([self._get_filename()])
147
self._parser = parser
144
if self._parser is None:
146
self._parser = ConfigObj(input)
147
except ConfigObjError, e:
148
raise errors.ParseConfigError(e.errors, e.config.filename)
150
151
def _get_section(self):
151
152
"""Override this to define the section used by the config."""
155
def _config_val(self, name, section=None):
157
section = self._get_section()
160
# Throw KeyError if name or section not present
161
if section == "DEFAULT":
163
return self._get_parser()[name]
166
return self._get_parser()[section][name]
168
def _config_bool(self, name, section=None):
169
val = self._config_val(name, section).lower()
170
if val in ('1', 'yes', 'true', 'on'):
172
elif val in ('0', 'no', 'false', 'off'):
175
raise ValueError("Value %r is not boolean" % val)
154
179
def _get_signature_checking(self):
155
180
"""See Config._get_signature_checking."""
156
section = self._get_section()
182
policy = self._config_val('check_signatures')
159
if self._get_parser().has_option(section, 'check_signatures'):
160
return self._string_to_signature_policy(
161
self._get_parser().get(section, 'check_signatures'))
185
return self._string_to_signature_policy(policy)
163
187
def _get_user_id(self):
164
188
"""Get the user id from the 'email' key in the current section."""
165
section = self._get_section()
166
if section is not None:
167
if self._get_parser().has_option(section, 'email'):
168
return self._get_parser().get(section, 'email')
190
return self._config_val('email')
170
194
def __init__(self, get_filename):
171
195
super(IniBasedConfig, self).__init__()
188
212
"""The configuration that should be used for a specific location."""
190
214
def get_editor(self):
191
if self._get_parser().has_option(self._get_section(), 'editor'):
192
return self._get_parser().get(self._get_section(), 'editor')
216
return self._config_val('editor')
194
220
def __init__(self):
195
221
super(GlobalConfig, self).__init__(config_filename)
239
265
# if path is longer, and recurse is not true, no match
240
266
if len(section_names) < len(location_names):
241
if (self._get_parser().has_option(section, 'recurse')
242
and not self._get_parser().getboolean(section, 'recurse')):
268
if not self._config_bool('recurse', section=section):
244
272
matches.append((len(section_names), section))
245
273
if not len(matches):