diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/Config.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/util/Config.py b/util/Config.py index 7bc8dff..0349e3e 100644 --- a/util/Config.py +++ b/util/Config.py @@ -12,7 +12,7 @@ def loadConfigFile(fileName): #TODO: error handling etc. if '.params' in fileName: return fileToDict(fileName) if '.xml' in fileName: - config = ElementTree() + config = ElementTree() #use .fromstring, and resolve xincludes config.parse(fileName) return config #except: @@ -81,3 +81,29 @@ def generateArgDict(parentNode, recurse=False): if len(args.keys()) == 1 and recurse: return args[args.keys()[0]] return args +def compositeXMLTrees(parentTree, overridingTree): + #type checking -- convert ElementTrees to their root elements + parentItems = parentTree.getchildren() + overrideItems = overridingTree.getchildren() + #first, lets figure out what tags we have in the override tree: + tagCollection = [el.tag for el in overrideItems] #we can speed this up with a dict if necessary + overrideRoot = overridingTree.getroot() + for item in parentItems: + if not item.tag in tagCollection: #no override + overrideRoot.insert(-1, item) #insert the new item at the end + else: + #do we merge or replace? + intersectingElements = findElementsByTag(item.tag, overrideItems) + if len(intersectingItems) > 1: + print 'ABUSE!' + interEl = intersectingElements[0] + mode = 'Replace' + if Strings.OVERRIDE_BEHAVIOR in interEl.attrib: + mode = interEl.attrib[Strings.OVERRIDE_BEHAVIOR] + if mode != 'Replace' and mode != 'Merge': + print 'Bad Mode. Replacing' + mode = 'Replace' + if mode = 'Replace': + pass #we don't need to do anything + if mode = 'Merge': + pass #TODO: code this |