aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2010-12-25 13:42:25 -0500
committerGravatar rcoh <rcoh@mit.edu>2010-12-25 13:42:25 -0500
commit1786a0e660f299f1608dd2e8087843e71de8fb3f (patch)
tree21e614675cbd0dcf3851322fe76e93e4ba6b0f36 /util
parent87a01a8e45cd332221ec510263b72d31d6b0759d (diff)
early stages. WARNING: THIS COMMIT DOESN'T NECESSARILY WORK. Sorry.
RCOH
Diffstat (limited to 'util')
-rw-r--r--util/Config.py30
-rw-r--r--util/Strings.py5
2 files changed, 35 insertions, 0 deletions
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