white space change
[sfa.git] / rspec / rspecvalidate.py
1 #!/usr/bin/python
2
3 # $HeadURL$
4 # $Id$
5
6 #
7 # Validate RSPEC hiearchy, values, types, and names using supplied xsd.
8 #
9 # Faiyaz Ahmed <faiyaza at cs dot princeton dot edu>
10 #
11 # Copyright 2009 Princeton University
12 # http://www.planet-lab.org
13 #
14
15 import sys
16 from xml.dom import minidom
17
18
19 def getText(nodelist):
20     rc = ""
21     for node in nodelist:
22         if node.nodeType == node.TEXT_NODE:
23             rc = rc + node.data
24     return rc
25
26 # complexType: a supernode comprised of element nodes below it.
27 def traverseComplexType(cmpTypeNode):
28         _elements = {}
29         if cmpTypeNode.hasChildNodes():
30                 for n in cmpTypeNode.getElementsByTagName("xsd:attribute"):
31                         _elements[n.getAttribute("name")] = {'type': n.getAttribute("type")}
32
33
34 # Element.  {name, value, default}
35 def Element(elementDom):
36         node = {} #parsed dict
37         for attr in elementDom.attributes.keys():
38                 node[attr] = elementDom.attributes.get(attr).value
39         return node
40
41 # Sequence is a list of dicts.  Each dict is an element type with Type fields
42 def Sequence(sequenceNode):
43         pass
44
45 def buildDict(document):
46         if document.hasChildNodes():
47                 for i in document.childNodes: buildDict(i)
48         print document.localName
49
50 def main(fname):
51         buildDict(minidom.parse(fname))
52
53 if __name__ == '__main__':  
54         main(fname="planetlab.xsd")