-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
95 lines (79 loc) · 2.55 KB
/
generator.py
File metadata and controls
95 lines (79 loc) · 2.55 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'''
The generator for node.js binding
'''
import xml.sax
import sys
import pprint
macro = {}
function = {}
enum = {}
class LibvirtHandler(xml.sax.ContentHandler):
''' Parse given XML'''
def __init__(self):
self.start = 0
self.data = {'args':[]}
self.title = ""
self.file = ""
self.name = ""
self.info = ""
# Call when an element starts
def startElement(self, tag, attr):
if tag == "symbols":
self.start = 1
if self.start == 0:
return
for k in attr._attrs:
attr._attrs[k] = str(attr._attrs[k])
if tag == "macro" or tag == "function" or tag == "enum":
self.title = tag
self.name = attr['name']
self.file = attr['file']
if tag == "macro" and self.file not in macro:
macro[self.file] = {}
if tag == "function" and self.file not in function:
function[self.file] = {}
if tag == "enum" and self.file not in enum:
enum[self.file] = {}
if tag == "arg":
self.data["args"] += [attr['name']]
#self.data["args"] += [(attr['name'], attr['info'])]
if tag == "enum":
enum[attr['file']][attr['name']] = attr['value']
if tag == "return":
self.data["return"] = attr['type']
#self.data["return"] = (attr['type'], attr['info'] if 'info' in attr else ' ')
# Call when an elements ends
def endElement(self, tag):
if self.start == 0:
return
if tag == "macro" or tag == "function":
#self.data["info"] = self.info
if tag == "macro":
macro[self.file][self.name] = self.data
if tag == "function":
function[self.file][self.name] = self.data
self.data = {'args':[]}
self.title = ""
self.name = ""
self.file = ""
# Call when a character is read
def characters(self, content):
if self.start == 0:
return
self.info += content
if __name__ == "__main__":
pp = pprint.PrettyPrinter(indent=4)
# create an XMLReader
parser = xml.sax.make_parser()
# turn off namepsaces
parser.setFeature(xml.sax.handler.feature_namespaces, 0)
# override the default ContextHandler
Handler = LibvirtHandler()
parser.setContentHandler(Handler)
parser.parse(sys.argv[1])
print "function"
pp.pprint (function)
print "macro"
pp.pprint (macro)
print "enum"
pp.pprint (enum)