Revision 7441bb96
b/qa/qa_config.py | ||
---|---|---|
45 | 45 |
_QA_BASE_PATH = os.path.dirname(__file__) |
46 | 46 |
_QA_DEFAULT_PATCH = "qa-patch.json" |
47 | 47 |
_QA_PATCH_DIR = "patch" |
48 |
_QA_PATCH_ORDER_FILE = "order" |
|
48 | 49 |
|
49 | 50 |
#: QA configuration (L{_QaConfig}) |
50 | 51 |
_config = None |
... | ... | |
296 | 297 |
def ApplyPatches(data, patch_module, patches): |
297 | 298 |
"""Applies any patches present, and returns the modified QA configuration. |
298 | 299 |
|
299 |
First, patches from the patch directory are applied, ordered alphabetically |
|
300 |
by name. |
|
300 |
First, patches from the patch directory are applied. They are ordered |
|
301 |
alphabetically, unless there is an ``order`` file present - any patches |
|
302 |
listed within are applied in that order, and any remaining ones in |
|
303 |
alphabetical order again. Finally, the default patch residing in the |
|
304 |
top-level QA directory is applied. |
|
301 | 305 |
|
302 | 306 |
@type data: dict (deserialized json) |
303 | 307 |
@param data: The QA configuration |
... | ... | |
309 | 313 |
@return: The modified configuration data. |
310 | 314 |
|
311 | 315 |
""" |
316 |
ordered_patches = [] |
|
317 |
order_path = os.path.join(_QA_BASE_PATH, _QA_PATCH_DIR, |
|
318 |
_QA_PATCH_ORDER_FILE) |
|
319 |
if os.path.exists(order_path): |
|
320 |
order_file = open(order_path, 'r') |
|
321 |
ordered_patches = order_file.read().splitlines() |
|
322 |
# Removes empty lines |
|
323 |
ordered_patches = filter(None, ordered_patches) |
|
324 |
|
|
325 |
# Add the patch dir |
|
326 |
ordered_patches = map(lambda x: os.path.join(_QA_PATCH_DIR, x), |
|
327 |
ordered_patches) |
|
328 |
|
|
329 |
# First the ordered patches |
|
330 |
for patch in ordered_patches: |
|
331 |
if patch not in patches: |
|
332 |
raise qa_error.Error("Patch %s specified in the ordering file does not " |
|
333 |
"exist" % patch) |
|
334 |
data = patch_module.apply_patch(data, patches[patch]) |
|
335 |
|
|
336 |
# Then the other non-default ones |
|
312 | 337 |
for patch in sorted(patches): |
313 |
if patch != _QA_DEFAULT_PATCH: |
|
338 |
if patch != _QA_DEFAULT_PATCH and patch not in ordered_patches:
|
|
314 | 339 |
data = patch_module.apply_patch(data, patches[patch]) |
315 | 340 |
|
341 |
# Finally the default one |
|
316 | 342 |
if _QA_DEFAULT_PATCH in patches: |
317 | 343 |
data = patch_module.apply_patch(data, patches[_QA_DEFAULT_PATCH]) |
318 | 344 |
|
Also available in: Unified diff