7 def dom_debug (node,level):
8 print level,'<<< dom_debug 1>>>',node.nodeType
9 # print level,'<<< dom_debug 2>>>',dir(node)
10 # print level,'<<< dom_debug 4>>>',node.nodeValue
11 for child in node.childNodes:
12 dom_debug (child,level+1)
13 print level,'<<end>>',len(node.childNodes)
15 # returns node's value - tries to be flexible
16 def dom_get_text (node):
18 if node.nodeType == node.TEXT_NODE:
20 elif node.nodeType == node.ELEMENT_NODE and len(node.childNodes) == 1:
21 return dom_get_text(node.childNodes[0])
22 elif node.nodeType == node.ELEMENT_NODE:
23 return 'dom_get_text: element does not have 1 child'
28 def __init__ (self, filename):
29 self.filename=filename
31 impl = xml.dom.minidom.getDOMImplementation()
32 self.dom = impl.createDocument (None, 'slices', None)
37 self.doc = xml.dom.minidom.parse(self.filename)
39 def scan_rspecs (self):
42 for slice in self.doc.getElementsByTagName('slice'):
44 resources = slice.getElementsByTagName('rspec')[0]
45 for resource in resources.getElementsByTagName('resource'):
46 value=resource.getElementsByTagName('value')[0]
47 rspecs.append({ 'name': value.getAttribute('name'),
48 'type':value.getAttribute('type'),
49 'value':dom_get_text(value) } )
51 slices [slice.getAttribute('name')] = rspecs
55 if __name__ == '__main__':
57 for filename in sys.argv[1:]:
58 export = SlicesParse(filename)
63 print 'parsing : %d seconds'%(now-start)
66 slices=export.scan_rspecs()
68 print 'scanning : %d seconds'%(now-start)
71 storage=open(filename+".bin","wb")
73 pickle.dump(slices,storage)
75 print 'storage : %d seconds'%(now-start)