diff options
author | rcoh <rcoh@mit.edu> | 2011-02-19 00:38:03 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2011-02-19 00:38:03 -0500 |
commit | 58ec94a477f5edef0bf75a60252af96adec34d8d (patch) | |
tree | 560e7d7676f5f14b738bae660b7485653ddedb46 | |
parent | cb69d2e1c7ced951cbf7a31ee286b0ed92cab8a8 (diff) |
Added XML introspection script (XmlInfo.py). Should make reading XML files a lot easier for us
humans!
-rw-r--r-- | XmlInfo.py | 47 | ||||
-rw-r--r-- | tests/testdata/XmlInfoTest.xml | 30 |
2 files changed, 77 insertions, 0 deletions
diff --git a/XmlInfo.py b/XmlInfo.py new file mode 100644 index 0000000..59ece57 --- /dev/null +++ b/XmlInfo.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +import util.Config as config +import util.Search as search +import sys +"""XmlInfo.py is a module for quick introspection of XML Documents. It will print all the Ids of +the components defined in an XML document and (if possible) their Doc strings. Usage: + python XmlInfo.py [fileName] [-b] [-i] + Example: + python XmlInfo.py config/C5Sign.xml + +With no flags all components are printed. With -b, behaviors are printed. With -i, inputs are +printed. (And both if both are specified) +""" +def loadFile(args): + fileName = args[1] + parentTags = [] + if '-b' in args: + parentTags.append('BehaviorConfiguration') + if '-i' in args: + parentTags.append('InputConfiguration') + if not parentTags: + parentTags = ['InputConfiguration', 'BehaviorConfiguration','PixelConfiguration', + 'RendererConfiguration'] + confRoot = config.loadConfigFile(fileName).getroot() + for tag in parentTags: + subTree = confRoot.find(tag) + print tag + ':' + nodesWithArgs = search.parental_tree_search(subTree,'.getchildren()', ".tag=='Args'") + nodesWithDocs = search.parental_tree_search(subTree,'.getchildren()', ".tag=='Doc'") + for obj in nodesWithArgs: + args = obj.find('Args') + cidEl = args.find('Id') + docEl = args.find('Doc') or obj.find('Doc') + classEl = obj.find('Class') + cid = None + doc = None + className = None + if cidEl != None: + cid = cidEl.text + if docEl != None: + doc = docEl.text + if classEl != None: + className = classEl.text + print '\tComponent %(id)s - Doc: %(doc)s - Class: %(class)s' % {'id':cid, 'doc':doc, + 'class':className} +if __name__ == "__main__": + loadFile(sys.argv) diff --git a/tests/testdata/XmlInfoTest.xml b/tests/testdata/XmlInfoTest.xml new file mode 100644 index 0000000..c79896a --- /dev/null +++ b/tests/testdata/XmlInfoTest.xml @@ -0,0 +1,30 @@ +<LightInstallation> + <InstallationConfiguration> + <Defaults> + <PixelMapper>simplemap</PixelMapper> + </Defaults> + </InstallationConfiguration> + <PixelConfiguration> + <InheritsFrom>layouts/C5SignLayout.xml</InheritsFrom> + </PixelConfiguration> + <PixelMapperConfiguration> + <PixelMapper> + <Class>pixelmappers.C5SignMapper</Class> + <Args> + <Id>simplemap</Id> + <CutoffDist>20</CutoffDist> + <Doc>SimpleMapper is a mapper which returns the closest pixel.</Doc> + </Args> + </PixelMapper> + <PixelMapper> + <Class>pixelmappers.GaussianMapper</Class> + <Args> + <Id>gaussmap</Id> + <CutoffDist>30</CutoffDist> + <MinWeight>0.1</MinWeight> + <Width>7</Width> + <Height>1</Height> + </Args> + </PixelMapper> + </PixelMapperConfiguration> +</LightInstallation> |