From: Gbkng Date: Thu, 11 Apr 2024 11:57:39 +0000 (+0200) Subject: feat: mordernize doxy2swig script X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=030f0c24881c739836fdce8246973c7494cdfb8a;p=tools%2Fmedcoupling.git feat: mordernize doxy2swig script --- diff --git a/doc/developer/doxygen/doxy2swig/doxy2swig.py b/doc/developer/doxygen/doxy2swig/doxy2swig.py index f8499b449..6740ba9a0 100755 --- a/doc/developer/doxygen/doxy2swig/doxy2swig.py +++ b/doc/developer/doxygen/doxy2swig/doxy2swig.py @@ -32,25 +32,9 @@ output will be written (the file will be clobbered). 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 @@ -68,10 +52,9 @@ class Doxy2SWIG: 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'%\ @@ -80,14 +63,27 @@ class Doxy2SWIG: 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') @@ -268,7 +264,6 @@ class Doxy2SWIG: 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] @@ -326,10 +321,9 @@ class Doxy2SWIG: 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: @@ -381,12 +375,11 @@ class Doxy2SWIG: 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 @@ -447,8 +440,12 @@ def main(): 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()