]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
feat: mordernize doxy2swig script
authorGbkng <guillaume.brooking@gmail.com>
Thu, 11 Apr 2024 11:57:39 +0000 (13:57 +0200)
committerGbkng <guillaume.brooking@gmail.com>
Tue, 23 Apr 2024 07:48:25 +0000 (09:48 +0200)
doc/developer/doxygen/doxy2swig/doxy2swig.py

index f8499b449647ca45f350ef9048913860754c0749..6740ba9a0866eb7f674a8932e18905b348fd3aa2 100755 (executable)
@@ -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()