]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/docs/bin/simplify.py
2 #---------------------------------------------------------------------------
4 # Like simplify.xsl but using Python so a few non-standard conversions can
5 # also be done. (Currently it is still about the same as simplify.xsl...)
7 #---------------------------------------------------------------------------
14 DEST
="docs/xml/wxPython-metadata.xml"
21 Get the list of extension modules from setup.py
24 names
= [e
.name
[1:] for e
in setup
.wxpExtensions
]
29 def getAttr(node
, name
):
31 Get a value by name from the <attribute> elements in the SWIG XML output
33 path
= "./attributelist/attribute[@name='%s']/@value" % name
34 n
= node
.xpathEval2(path
)
44 def processModule(newDocNode
, modulename
):
46 Start processing a new XML file, create a module element and then
47 find the include elements
49 filename
= os
.path
.join(SRC
, "%s_swig.xml" % modulename
)
52 doc
= libxml2
.parseFile(filename
)
53 topNode
= doc
.getRootElement()
55 # make a module element
56 name
= getAttr(topNode
, "module")
57 assert name
== modulename
# sanity check
59 moduleNode
= libxml2
.newNode("module")
60 moduleNode
.setProp("name", name
)
61 newDocNode
.addChild(moduleNode
)
63 node
= topNode
.children
64 while node
is not None:
65 if node
.name
== "include":
66 processInclude(moduleNode
, node
)
73 def processInclude(moduleNode
, includeNode
):
75 Almost everything we are interested in is inside an <include>,
76 which may also be nested.
79 # check first for imports
80 for node
in includeNode
.xpathEval2("import"):
82 modNode
= node
.xpathEval2("module")[0]
83 name
= getAttr(modNode
, "name")
84 impNode
= libxml2
.newNode("import")
85 impNode
.setProp("name", name
)
86 moduleNode
.addChild(impNode
)
90 # then look through the child nodes for other things we need
91 node
= includeNode
.children
92 while node
is not None:
93 if node
.name
== "insert":
94 processInsert(moduleNode
, node
)
96 elif node
.name
== "class":
97 processClass(moduleNode
, node
)
99 elif node
.name
== "cdecl" and getAttr(node
, "view") == "globalfunctionHandler":
100 func
= libxml2
.newNode("method")
101 func
.setProp("name", getAttr(node
, "sym_name"))
102 func
.setProp("oldname", getAttr(node
, "name"))
103 func
.setProp("type", getAttr(node
, "type"))
104 doCheckOverloaded(func
, node
)
105 doDocStrings(func
, node
)
106 doParamList(func
, node
)
107 moduleNode
.addChild(func
)
110 elif node
.name
== "include":
111 processInclude(moduleNode
, node
)
117 def processInsert(parentNode
, insertNode
):
121 if getAttr(insertNode
, "section") == "python":
122 code
= getAttr(insertNode
, "code")
123 node
= libxml2
.newNode("pythoncode")
124 node
.addChild(libxml2
.newText(code
))
125 parentNode
.addChild(node
)
129 def processClass(parentNode
, classNode
):
131 Handle classes, constructors, methods, etc.
134 klass
= libxml2
.newNode("class")
135 klass
.setProp("name", getAttr(classNode
, "sym_name"))
136 klass
.setProp("oldname", getAttr(classNode
, "name"))
137 klass
.setProp("module", getAttr(classNode
, "module"))
138 doDocStrings(klass
, classNode
)
139 parentNode
.addChild(klass
)
141 # check for baseclass(es)
142 for node
in classNode
.xpathEval2("attributelist/baselist/base"):
143 baseclass
= libxml2
.newNode("baseclass")
144 baseclass
.setProp("name", node
.prop("name"))
145 klass
.addChild(baseclass
)
147 # check for constructors/destructors
148 for type in ["constructor", "destructor"]:
149 for node
in classNode
.xpathEval2("%s | extend/%s" % (type, type)):
150 func
= libxml2
.newNode(type)
151 func
.setProp("name", getAttr(node
, "sym_name"))
152 if parentNode
.name
!= "destructor":
153 doCheckOverloaded(func
, node
)
154 doDocStrings(func
, node
)
155 doParamList(func
, node
)
158 # check for cdecl's. In class scope we are interested in methods,
159 # static methods, or properties
160 for node
in classNode
.xpathEval2("cdecl | extend/cdecl"):
161 view
= getAttr(node
, "view")
162 if view
== "memberfunctionHandler":
163 func
= libxml2
.newNode("method")
164 func
.setProp("name", getAttr(node
, "sym_name"))
165 func
.setProp("type", getAttr(node
, "type"))
166 doCheckOverloaded(func
, node
)
167 doDocStrings(func
, node
)
168 doParamList(func
, node
)
171 elif view
== "staticmemberfunctionHandler":
172 func
= libxml2
.newNode("staticmethod")
173 func
.setProp("name", getAttr(node
, "sym_name"))
174 func
.setProp("type", getAttr(node
, "type"))
175 doCheckOverloaded(func
, node
)
176 doDocStrings(func
, node
)
177 doParamList(func
, node
)
180 elif view
== "variableHandler":
181 prop
= libxml2
.newNode("property")
182 prop
.setProp("name", getAttr(node
, "sym_name"))
183 prop
.setProp("type", getAttr(node
, "type"))
184 if getAttr(node
, "feature_immutable"):
185 prop
.setProp("readonly", "yes")
187 prop
.setProp("readonly", "no")
188 doDocStrings(prop
, node
)
193 def doParamList(parentNode
, srcNode
):
195 Convert the parameter list
197 params
= srcNode
.xpathEval2("attributelist/parmlist/parm")
199 plist
= libxml2
.newNode("paramlist")
201 pnode
= libxml2
.newNode("param")
202 pnode
.setProp("name", getAttr(p
, "name"))
203 pnode
.setProp("type", getAttr(p
, "type"))
204 pnode
.setProp("default", getAttr(p
, "value"))
205 plist
.addChild(pnode
)
206 parentNode
.addChild(plist
)
210 def doCheckOverloaded(parentNode
, srcNode
):
212 Set an attribute indicating if the srcNode is tagged as being overloaded
214 if srcNode
.xpathEval2("./attributelist/attribute[@name='sym_overloaded']"):
215 parentNode
.setProp("overloaded", "yes")
217 parentNode
.setProp("overloaded", "no")
221 def doDocStrings(parentNode
, srcNode
):
223 Check for the various possible docstring attributes, and attach
224 coresponding child nodes if found.
226 def makeDocElement(name
, content
):
227 node
= libxml2
.newNode(name
)
228 node
.addChild(libxml2
.newText(content
))
231 autodoc
= getAttr(srcNode
, "python_autodoc")
232 docstr
= getAttr(srcNode
, "feature_docstring")
233 refdoc
= getAttr(srcNode
, "feature_refdoc")
235 parentNode
.addChild(makeDocElement("autodoc", autodoc
))
237 parentNode
.addChild(makeDocElement("docstring", docstr
))
239 parentNode
.addChild(makeDocElement("refdoc", refdoc
))
246 if not os
.path
.exists(SRC
):
247 print "Unable to find %s, please run this script from the root wxPython directory." % SRC
250 newDoc
= libxml2
.newDoc("1.0")
251 newTopNode
= libxml2
.newNode("wxPython-metadata")
252 newDoc
.addChild(newTopNode
)
254 for m
in getModuleNames():
255 processModule(newTopNode
, m
)
257 newDoc
.saveFormatFile(DEST
, True)
260 #---------------------------------------------------------------------------
262 if __name__
== "__main__":