diff --git a/scripts/resources/repair.py b/scripts/resources/repair.py index 313ef7309..2d0242b4d 100755 --- a/scripts/resources/repair.py +++ b/scripts/resources/repair.py @@ -3,34 +3,35 @@ import sys from xml.dom import minidom +def getFirstElementFrom(node): + while node is not None and node.nodeType != minidom.Node.ELEMENT_NODE: + node = node.nextSibling + return node + def processNodes(base, custom): - customChild = custom.firstChild - for baseChild in base.childNodes: - if baseChild.nodeType != minidom.Node.ELEMENT_NODE: - continue - while customChild is not None and customChild.nodeType != minidom.Node.ELEMENT_NODE: - customChild = customChild.nextSibling + baseChild = getFirstElementFrom(base.firstChild) + customChild = getFirstElementFrom(custom.firstChild) + while baseChild is not None: if baseChild.nodeName == 'node': name = baseChild.getAttribute('name') - if name == '': - continue - if customChild is None or name != customChild.getAttribute('name'): + if name != '' and (customChild is None or name != customChild.getAttribute('name')): newNode = custom.ownerDocument.createElement('node') - newNode.setAttribute('name', name); + newNode.setAttribute('name', name) value = baseChild.getAttribute('value') if value != '': - newNode.setAttribute('value', value); - newNode.setAttribute('toBeTranslated', 'true'); + newNode.setAttribute('value', value) + newNode.setAttribute('toBeTranslated', 'true') customChild = custom.insertBefore(newNode, customChild) processNodes(baseChild, customChild) - customChild = customChild.nextSibling + baseChild = getFirstElementFrom(baseChild.nextSibling) + customChild = getFirstElementFrom(customChild.nextSibling) if len(sys.argv) != 3: print 'Usage: %s ' % sys.argv[0] exit(1) -base_model = minidom.parse(sys.argv[1]) -custom_model = minidom.parse(sys.argv[2]) +baseModel = minidom.parse(sys.argv[1]) +customModel = minidom.parse(sys.argv[2]) -processNodes(base_model, custom_model) -print custom_model.toxml('UTF-8') +processNodes(baseModel, customModel) +print customModel.toxml('UTF-8')