forked from rcoh/SmootLight
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXmlInfo.py
52 lines (51 loc) · 2.06 KB
/
XmlInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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 + ':\n'
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 and args != None:
argDict = config.pullArgsFromItem(obj)
doc = docEl.text
try:
doc = doc % argDict
except:
doc = docEl.text
if classEl != None:
className = classEl.text
print '\t%(id)s : %(class)s\n\t\t%(doc)s\n' % {'id':cid, 'doc':doc,
'class':className}
if __name__ == "__main__":
loadFile(sys.argv)