Preprocesses occurrences of Argument within the root. Argument XML values reference other values within the document by name. The referenced value does not contain a switch. This function will add the switch associated with the argument.
(root)
| 361 | |
| 362 | |
| 363 | def __preprocess_arguments(root): |
| 364 | """Preprocesses occurrences of Argument within the root. |
| 365 | |
| 366 | Argument XML values reference other values within the document by name. The |
| 367 | referenced value does not contain a switch. This function will add the |
| 368 | switch associated with the argument. |
| 369 | """ |
| 370 | # Set the flags to require a value |
| 371 | flags = ','.join(vsflags(VSFlags.UserValueRequired)) |
| 372 | |
| 373 | # Search through the arguments |
| 374 | arguments = root.getElementsByTagName('Argument') |
| 375 | |
| 376 | for argument in arguments: |
| 377 | reference = __get_attribute(argument, 'Property') |
| 378 | found = None |
| 379 | |
| 380 | # Look for the argument within the root's children |
| 381 | for child in root.childNodes: |
| 382 | # Ignore Text nodes |
| 383 | if isinstance(child, Element): |
| 384 | name = __get_attribute(child, 'Name') |
| 385 | |
| 386 | if name == reference: |
| 387 | found = child |
| 388 | break |
| 389 | |
| 390 | if found is not None: |
| 391 | logging.info('Found property named %s', reference) |
| 392 | # Get the associated switch |
| 393 | switch = __get_attribute(argument.parentNode, 'Switch') |
| 394 | |
| 395 | # See if there is already a switch associated with the element. |
| 396 | if __get_attribute(found, 'Switch'): |
| 397 | logging.debug('Copying node %s', reference) |
| 398 | clone = found.cloneNode(True) |
| 399 | root.insertBefore(clone, found) |
| 400 | found = clone |
| 401 | |
| 402 | found.setAttribute('Switch', switch) |
| 403 | found.setAttribute('Flags', flags) |
| 404 | else: |
| 405 | logging.warning('Could not find property named %s', reference) |
| 406 | |
| 407 | |
| 408 | def __get_attribute(node, name, default_value=''): |
no test coverage detected
searching dependent graphs…