From 1786a0e660f299f1608dd2e8087843e71de8fb3f Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 25 Dec 2010 13:42:25 -0500 Subject: early stages. WARNING: THIS COMMIT DOESN'T NECESSARILY WORK. Sorry. RCOH --- util/Config.py | 30 ++++++++++++++++++++++++++++++ util/Strings.py | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/util/Config.py b/util/Config.py index f80b7b2..bf1d5da 100644 --- a/util/Config.py +++ b/util/Config.py @@ -1,4 +1,5 @@ from xml.etree.ElementTree import ElementTree +import util.Strings as Strings classArgsMem = {} CONFIG_PATH = 'config/' def loadParamRequirementDict(className): @@ -16,6 +17,35 @@ def loadConfigFile(fileName): #TODO: error handling etc. return config #except: return None +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 + +def findElementsByTag(tag, eList): + return [el for el in eList if el.tag == tag] def fileToDict(fileName): fileText = '' try: diff --git a/util/Strings.py b/util/Strings.py index 81c34f2..698b4ec 100644 --- a/util/Strings.py +++ b/util/Strings.py @@ -1,2 +1,7 @@ LOCATION = 'Location' DEFAULT_MAPPER = 'DefaultPixelMapper' + + + +#XMLStuff +OVERRIDE_BEHAVIOR -- cgit v1.2.3