]>
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"
19 'wxString' : 'String',
26 Get the list of extension modules from setup.py
29 names
= [e
.name
[1:] for e
in setup
.wxpExtensions
]
34 def getAttr(node
, name
):
36 Get a value by name from the <attribute> elements in the SWIG XML output
38 path
= "./attributelist/attribute[@name='%s']/@value" % name
39 n
= node
.xpathEval2(path
)
48 Fixup type string, dropping the swig pointer and other flags
50 pos
= typeStr
.rfind('.')
52 typeStr
= typeStr
[pos
+1:]
53 return classMap
.get(typeStr
, typeStr
)
56 def processModule(newDocNode
, modulename
):
58 Start processing a new XML file, create a module element and then
59 find the include elements
61 filename
= os
.path
.join(SRC
, "%s_swig.xml" % modulename
)
64 doc
= libxml2
.parseFile(filename
)
65 topNode
= doc
.getRootElement()
67 # make a module element
68 name
= getAttr(topNode
, "module")
69 assert name
== modulename
# sanity check
71 moduleNode
= libxml2
.newNode("module")
72 moduleNode
.setProp("name", name
)
73 newDocNode
.addChild(moduleNode
)
75 node
= topNode
.children
76 while node
is not None:
77 if node
.name
== "include":
78 processInclude(moduleNode
, node
)
85 def processInclude(moduleNode
, includeNode
):
87 Almost everything we are interested in is inside an <include>,
88 which may also be nested.
91 # check first for imports
92 for node
in includeNode
.xpathEval2("import"):
94 modNode
= node
.xpathEval2("module")[0]
95 name
= getAttr(modNode
, "name")
96 impNode
= libxml2
.newNode("import")
97 impNode
.setProp("name", name
)
98 moduleNode
.addChild(impNode
)
102 # then look through the child nodes for other things we need
103 node
= includeNode
.children
104 while node
is not None:
105 if node
.name
== "insert":
106 processInsert(moduleNode
, node
)
108 elif node
.name
== "class":
109 processClass(moduleNode
, node
)
111 elif node
.name
== "cdecl" and getAttr(node
, "view") == "globalfunctionHandler":
112 func
= libxml2
.newNode("method")
113 func
.setProp("name", getAttr(node
, "sym_name"))
114 func
.setProp("oldname", getAttr(node
, "name"))
115 func
.setProp("type", fixType(getAttr(node
, "type")))
116 doCheckOverloaded(func
, node
)
117 doDocStrings(func
, node
)
118 doParamList(func
, node
)
119 moduleNode
.addChild(func
)
122 elif node
.name
== "include":
123 processInclude(moduleNode
, node
)
129 def processInsert(parentNode
, insertNode
):
133 if getAttr(insertNode
, "section") == "python":
134 code
= getAttr(insertNode
, "code")
135 node
= libxml2
.newNode("pythoncode")
136 node
.addChild(libxml2
.newText(code
))
137 parentNode
.addChild(node
)
141 def processClass(parentNode
, classNode
):
143 Handle classes, constructors, methods, etc.
146 klass
= libxml2
.newNode("class")
147 name
= getAttr(classNode
, "sym_name")
148 oldname
= getAttr(classNode
, "name")
149 classMap
[oldname
] = name
150 klass
.setProp("name", name
)
151 klass
.setProp("oldname", oldname
)
152 klass
.setProp("module", getAttr(classNode
, "module"))
153 doDocStrings(klass
, classNode
)
154 parentNode
.addChild(klass
)
156 # check for baseclass(es)
157 for node
in classNode
.xpathEval2("attributelist/baselist/base"):
158 baseclass
= libxml2
.newNode("baseclass")
159 basename
= node
.prop("name")
160 baseclass
.setProp("name", classMap
.get(basename
, basename
))
161 klass
.addChild(baseclass
)
163 # check for constructors/destructors
164 for type in ["constructor", "destructor"]:
165 for node
in classNode
.xpathEval2("%s | extend/%s" % (type, type)):
166 func
= libxml2
.newNode(type)
167 func
.setProp("name", getAttr(node
, "sym_name"))
168 if parentNode
.name
!= "destructor":
169 doCheckOverloaded(func
, node
)
170 doDocStrings(func
, node
)
171 doParamList(func
, node
)
174 # check for cdecl's. In class scope we are interested in methods,
175 # static methods, or properties
176 for node
in classNode
.xpathEval2("cdecl | extend/cdecl"):
177 view
= getAttr(node
, "view")
178 if view
== "memberfunctionHandler":
179 func
= libxml2
.newNode("method")
180 func
.setProp("name", getAttr(node
, "sym_name"))
181 func
.setProp("type", fixType(getAttr(node
, "type")))
182 doCheckOverloaded(func
, node
)
183 doDocStrings(func
, node
)
184 doParamList(func
, node
)
187 elif view
== "staticmemberfunctionHandler":
188 func
= libxml2
.newNode("staticmethod")
189 func
.setProp("name", getAttr(node
, "sym_name"))
190 func
.setProp("type", fixType(getAttr(node
, "type")))
191 doCheckOverloaded(func
, node
)
192 doDocStrings(func
, node
)
193 doParamList(func
, node
)
196 elif view
== "variableHandler":
197 prop
= libxml2
.newNode("property")
198 prop
.setProp("name", getAttr(node
, "sym_name"))
199 prop
.setProp("type", fixType(getAttr(node
, "type")))
200 if getAttr(node
, "feature_immutable"):
201 prop
.setProp("readonly", "yes")
203 prop
.setProp("readonly", "no")
204 doDocStrings(prop
, node
)
209 def doParamList(parentNode
, srcNode
):
211 Convert the parameter list
213 params
= srcNode
.xpathEval2("attributelist/parmlist/parm")
215 plist
= libxml2
.newNode("paramlist")
217 pnode
= libxml2
.newNode("param")
218 pnode
.setProp("name", getAttr(p
, "name"))
219 pnode
.setProp("type", fixType(getAttr(p
, "type")))
220 pnode
.setProp("default", getAttr(p
, "value"))
221 plist
.addChild(pnode
)
222 parentNode
.addChild(plist
)
226 def doCheckOverloaded(parentNode
, srcNode
):
228 Set an attribute indicating if the srcNode is tagged as being overloaded
230 if srcNode
.xpathEval2("./attributelist/attribute[@name='sym_overloaded']"):
231 parentNode
.setProp("overloaded", "yes")
233 parentNode
.setProp("overloaded", "no")
237 def doDocStrings(parentNode
, srcNode
):
239 Check for the various possible docstring attributes, and attach
240 coresponding child nodes if found.
242 def makeDocElement(name
, content
):
243 node
= libxml2
.newNode(name
)
244 node
.addChild(libxml2
.newText(content
))
247 autodoc
= getAttr(srcNode
, "python_autodoc")
248 docstr
= getAttr(srcNode
, "feature_docstring")
249 refdoc
= getAttr(srcNode
, "feature_refdoc")
251 parentNode
.addChild(makeDocElement("autodoc", autodoc
))
253 parentNode
.addChild(makeDocElement("docstring", docstr
))
255 parentNode
.addChild(makeDocElement("refdoc", refdoc
))
262 if not os
.path
.exists(SRC
):
263 print "Unable to find %s, please run this script from the root wxPython directory." % SRC
266 newDoc
= libxml2
.newDoc("1.0")
267 newTopNode
= libxml2
.newNode("wxPython-metadata")
268 newDoc
.addChild(newTopNode
)
270 for m
in getModuleNames():
271 processModule(newTopNode
, m
)
273 newDoc
.saveFormatFile(DEST
, True)
274 print "Wrote simplified metadata to", DEST
276 #---------------------------------------------------------------------------
278 if __name__
== "__main__":