]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/doxymlparser.py
Commit script which parses the Doxygen XML output into a list of class and method...
[wxWidgets.git] / docs / doxygen / doxymlparser.py
CommitLineData
f613f81a
KO
1"""
2Name: doxymlparser.py
3Author: Kevin Ollivier
4License: wxWidgets License
5"""
6
7__description__ = """
8Takes the output of Doxygen XML and parses it to retrieve metadata about the classes and methods.
9
10To create the Doxygen XML files, from the wxWidgets/docs/doxygen directory, do:
11
12./regen.sh xml
13
14To see the results from parsing a particular class, do:
15
16python doxymlparser.py --report out/xml/classwx_<whatever>.xml
17"""
18
19#!/usr/bin/env python
20import optparse
21import os
22import string
23
24import sys
25import types
26from xml.dom import minidom
27
28option_dict = {
29 "report" : (False, "Print out the classes and methods found by this script."),
30 }
31
32parser = optparse.OptionParser(usage="usage: %prog [options] <doxyml files to parse>\n" + __description__, version="%prog 1.0")
33
34for opt in option_dict:
35 default = option_dict[opt][0]
36
37 action = "store"
38 if type(default) == types.BooleanType:
39 action = "store_true"
40 parser.add_option("--" + opt, default=default, action=action, dest=opt, help=option_dict[opt][1])
41
42options, arguments = parser.parse_args()
43
44class ClassDefinition:
45 def __init__(self):
46 self.name = ""
47 self.methods = []
48 self.brief_description = ""
49 self.detailed_description = ""
50 self.includes = []
51 self.bases = []
52
53 def __str__(self):
54 str_repr = """
55Class: %s
56Bases: %s
57Inlcudes: %s
58Brief Description:
59%s
60
61Detailed Description:
62%s
63""" % (self.name, string.join(self.bases, ", "), self.includes, self.brief_description, self.detailed_description)
64 str_repr += "Methods:\n"
65
66 for method in self.methods:
67 str_repr += str(method)
68
69 return str_repr
70
71class MethodDefinition:
72 def __init__(self):
73 self.name = ""
74 self.return_type = ""
75 self.argsstring = ""
76 self.definition = ""
77 self.params = []
78 self.brief_description = ""
79 self.detailed_description = ""
80
81 def __str__(self):
82 str_repr = """
83Method: %s
84Return Type: %s
85Params: %r
86Prototype: %s
87Brief Description:
88%s
89
90Detailed Description:
91%s
92""" % (self.name, self.return_type, self.params, self.definition + self.argsstring, self.brief_description, self.detailed_description)
93 return str_repr
94
95def getTextValue(node, recursive=False):
96 text = ""
97 for child in node.childNodes:
98 if child.nodeType == child.TEXT_NODE:
99 text += child.nodeValue.strip()
100
101 return text
102
103def doxyMLToText(node):
104 return text
105
106class DoxyMLParser:
107 def __init__(self):
108 self.classes = []
109
110 def parse(self, filename):
111 self.xmldoc = minidom.parse(filename).documentElement
112 for node in self.xmldoc.getElementsByTagName("compounddef"):
113 self.classes.append(self.parse_class(node))
114
115 def parse_class(self, class_node):
116 new_class = ClassDefinition()
117 for node in class_node.childNodes:
118 if node.nodeName == "compoundname":
119 new_class.name = getTextValue(node)
120 print "Parsing class %s" % new_class.name
121 elif node.nodeName == "basecompoundref":
122 new_class.bases.append(getTextValue(node))
123 elif node.nodeName == "briefdescription":
124 # let the post-processor determ
125 new_class.brief_description = node.toxml()
126 elif node.nodeName == "detaileddescription":
127 new_class.detailed_description = node.toxml()
128
129 self.parse_methods(new_class, class_node)
130 return new_class
131
132 def parse_methods(self, new_class, root):
133 for method in root.getElementsByTagName("memberdef"):
134 new_method = MethodDefinition()
135 for node in method.childNodes:
136 if node.nodeName == "name":
137 new_method.name = getTextValue(node)
138 elif node.nodeName == "type":
139 new_method.return_type = getTextValue(node)
140 elif node.nodeName == "definition":
141 new_method.definition = getTextValue(node)
142 elif node.nodeName == "argsstring":
143 new_method.argsstring = getTextValue(node)
144 elif node.nodeName == "param":
145 param = {}
146 for child in node.childNodes:
147 if child.nodeType == child.ELEMENT_NODE:
148 param[child.nodeName] = getTextValue(child)
149 new_method.params.append(param)
150 new_class.methods.append(new_method)
151
152if __name__ == "__main__":
153 if len(arguments) < 1:
154 parser.print_usage()
155 sys.exit(1)
156
157 doxyparse = DoxyMLParser()
158 for arg in arguments:
159 doxyparse.parse(arg)
160
161 if options.report:
162 for aclass in doxyparse.classes:
163 print str(aclass)
164