from xml.dom import minidom
import re
import textwrap
-import sys
-import types
import os.path
import optparse
-
-def my_open_read(source):
- if hasattr(source, "read"):
- return source
- else:
- return open(source)
-
-def my_open_write(dest):
- if hasattr(dest, "write"):
- return dest
- else:
- return open(dest, 'w')
-
-
class Doxy2SWIG:
"""Converts Doxygen generated XML files into a file containing
docstrings that can be used by SWIG-1.3.x that have support for
using %feature("autodoc", [0,1]).
"""
- f = my_open_read(src)
- self.my_dir = os.path.dirname(f.name)
- self.xmldoc = minidom.parse(f).documentElement
- f.close()
+ with open(src, 'r') as f:
+ self.my_dir = os.path.dirname(f.name)
+ self.xmldoc = minidom.parse(f).documentElement
self.pieces = []
self.pieces.append('\n// File: %s\n'%\
self.space_re = re.compile(r'\s+')
self.lead_spc = re.compile(r'^(%feature\S+\s+\S+\s*?)"\s+(\S)')
self.multi = 0
- self.ignores = ['inheritancegraph', 'param', 'listofallmembers',
- 'innerclass', 'name', 'declname', 'incdepgraph',
- 'invincdepgraph', 'programlisting', 'type',
- 'references', 'referencedby', 'location',
- 'collaborationgraph', 'reimplements',
- 'reimplementedby', 'derivedcompoundref',
- 'basecompoundref']
- #self.generics = []
+ self.ignores = [
+ "inheritancegraph",
+ "param",
+ "listofallmembers",
+ "innerclass",
+ "name",
+ "declname",
+ "incdepgraph",
+ "invincdepgraph",
+ "programlisting",
+ "type",
+ "references",
+ "referencedby",
+ "location",
+ "collaborationgraph",
+ "reimplements",
+ "reimplementedby",
+ "derivedcompoundref",
+ "basecompoundref",
+ ]
+
self.include_function_definition = include_function_definition
if not include_function_definition:
self.ignores.append('argsstring')
def do_memberdef(self, node):
prot = node.attributes['prot'].value
- id = node.attributes['id'].value
kind = node.attributes['kind'].value
tmp = node.parentNode.parentNode.parentNode
compdef = tmp.getElementsByTagName('compounddef')[0]
which should not be printed as such, so we comment it in the
output."""
data = node.firstChild.data
- self.add_text('\n/*\n %s \n*/\n'%data)
- # If our immediate sibling is a 'description' node then we
- # should comment that out also and remove it from the parent
- # node's children.
+ self.add_text("\n/*\n %s \n*/\n" % data)
+ # If our immediate sibling is a 'description' node, we should comment
+ # that out also and remove it from the parent node's children.
parent = node.parentNode
idx = parent.childNodes.index(node)
if len(parent.childNodes) >= idx + 2:
self.pieces.extend(self.clean_pieces(p.pieces))
def write(self, fname):
- o = my_open_write(fname)
- if self.multi:
- o.write("".join(self.pieces))
- else:
- o.write("".join(self.clean_pieces(self.pieces)))
- o.close()
+ with open(fname, 'w') as o:
+ if self.multi:
+ o.write("".join(self.pieces))
+ else:
+ o.write("".join(self.clean_pieces(self.pieces)))
def clean_pieces(self, pieces):
"""Cleans the list of strings given as `pieces`. It replaces
if len(args) != 2:
parser.error("error: no input and output specified")
- convert(args[0], args[1], not options.func_def, options.quiet)
-
+ convert(
+ input=args[0],
+ output=args[1],
+ include_function_definition=not options.func_def,
+ quiet=options.quiet,
+ )
if __name__ == '__main__':
main()