From 2113f5363022e4ccb2b14d0a7ebd6765de820411 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 25 Dec 2010 13:51:25 -0500 Subject: Early stages of support for config inheritance. MIGHT NOT WORK! Sorry. -RCOH --- util/Config.py | 26 ++++++++++++++++++++++++++ util/Strings.py | 1 + 2 files changed, 27 insertions(+) (limited to 'util') diff --git a/util/Config.py b/util/Config.py index 55da1b4..746350d 100644 --- a/util/Config.py +++ b/util/Config.py @@ -51,3 +51,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 diff --git a/util/Strings.py b/util/Strings.py index 1331db4..d58202d 100644 --- a/util/Strings.py +++ b/util/Strings.py @@ -1 +1,2 @@ LOCATION = 'Location' +OVERRIDE_BEHAVIOR = 'OverrideBehavior' -- cgit v1.2.3