@@ -57,7 +57,7 @@ def subtests_subsubtests(subthing_set, subtest_modules):
57
57
subtest_to_subsubtest = {}
58
58
for subthing in subthing_set:
59
59
parent = subtest_of_subsubtest(subthing, subtest_modules)
60
- if parent == None:
60
+ if parent is None:
61
61
subtest = subthing
62
62
subsubtest = set()
63
63
else:
@@ -153,64 +153,62 @@ class ControlINI(ConfigParser.SafeConfigParser, Singleton):
153
153
Representation of control settings
154
154
"""
155
155
156
- # Default relative locations for control settings files
157
- CONTROL_INI_DEFAULT = "config_defaults/control.ini"
158
- CONTROL_INI_CUSTOM = "config_custom/control.ini"
159
-
160
- # Mapping of option-name to section name (for generating defaults)
161
- OPT_SEC_MAP = {'include': 'Control',
162
- 'exclude': 'Control',
163
- 'subthings': 'Control',
164
- 'pretests': 'Control',
165
- 'subtests': 'Control',
166
- 'intratests': 'Control',
167
- 'posttests': 'Control',
168
- 'url': 'Bugzilla',
169
- 'username': 'Bugzilla',
170
- 'password': 'Bugzilla',
171
- 'excluded': 'Bugzilla',
172
- 'key_field': 'Bugzilla',
173
- 'key_match': 'Bugzilla',}
174
-
175
- # Absolute base path where all other relative paths reside
156
+ # Absolute base path to prefix onto below
176
157
control_path = os.path.dirname(job.control)
177
158
159
+ # Default relative locations, prefixed by above
160
+ control_ini_default = os.path.join(control_path,
161
+ "config_defaults/control.ini")
162
+ control_ini_custom = os.path.join(control_path,
163
+ "config_custom/control.ini")
164
+
178
165
# Default location where write() writes to if no file given
179
166
write_path = job.resultdir
180
167
181
168
# Token that signals not to execute tests
182
169
NOEXECTOK = '!!!'
183
170
184
171
def __init__(self):
185
- # Help catch missing options in defaults but not in OPT_SEC_MAP
186
- # by making them None instead of ''
187
- super(ControlINI, self).__init__(allow_no_value=True)
172
+ # Inject defaults dict into ancestor's initialization
173
+ super(ControlINI, self).__init__(self.defaults(), allow_no_value=True)
188
174
self.optionxform = str # support case-sensitive options
189
- for option, section in self.OPT_SEC_MAP.iteritems():
190
- try:
191
- self.add_section(section)
192
- except ConfigParser.DuplicateSectionError:
193
- pass # already existing section
194
- # Empty string is the default value
195
- self.set(section, option, '')
196
- # These option values default to the option name, look up section
197
- for key in ('pretests', 'subtests ', 'intratests ', 'posttests'):
198
- self.set(self.OPT_SEC_MAP[key], key, key )
175
+
176
+ def defaults(self): # Part of the ConfigParser interface
177
+ """Return a dictionary containing the instance-wide defaults."""
178
+ return dict(include='', exclude='', subthings='',
179
+ pretests='pretests', subtests='subtests',
180
+ intratests='intratests', posttests='posttests',
181
+ url='', username='', password='',
182
+ excluded='', key_field='',
183
+ key_match=' ', product=' ', component='',
184
+ status='' )
199
185
200
186
def read(self, filenames=None):
201
187
"""
202
- Read CONTROL_INI_DEFAULT or CONTROL_INI_CUSTOM if filenames is None
203
- """
204
- if filenames is None:
205
- control_ini_default = os.path.join(self.control_path,
206
- self.CONTROL_INI_DEFAULT)
207
- control_ini_custom = os.path.join(self.control_path,
208
- self.CONTROL_INI_CUSTOM)
209
- filenames = [control_ini_default, control_ini_custom]
210
- result = super(ControlINI, self).read(filenames)
211
- if len(result) == 0:
212
- result = ["<ControlINI defaults>"]
213
- logging.debug("Loaded control configuration from %s", str(result[-1]))
188
+ Read default and/or custom control.init plus filesnames
189
+
190
+ :param filenames: List of filenames to attempt to load (in order)
191
+ returns: Representation of loaded items
192
+ rtype: list
193
+ """
194
+ if filenames is None: # Preserve ancestor interface just in case
195
+ filenames = []
196
+ filenames.append(self.control_ini_custom)
197
+ result = ["<Empty Defaults>"]
198
+ # Try load defaults via readfp as documented
199
+ try:
200
+ with open(self.control_ini_default, 'rb') as defaults_file:
201
+ # readfp does _not_ merge content, defaults still
202
+ # used for missing keys, upon reference.
203
+ super(ControlINI, self).readfp(defaults_file)
204
+ result.append(defaults_file.name)
205
+ except IOError:
206
+ pass # Use defaults set from __init__()
207
+ # _merge_ any content from the last readable item in filenames
208
+ loaded = super(ControlINI, self).read(filenames)
209
+ if loaded:
210
+ result += loaded
211
+ logging.debug("Loaded control configuration from %s", result)
214
212
return result
215
213
216
214
def write(self, fileobject=None):
0 commit comments