2 # Copyright (C) 2017-2023 CEA, EDF, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from types import FunctionType
25 ORIGIN_MODULE_SUFFIX = "_origin"
26 DYNAMIC_MODULE_SUFFIX = "_dynamic"
29 def main(module_name, output_file = "smeshBuilder.py"):
30 oringin_module_name = module_name + ORIGIN_MODULE_SUFFIX
31 dynamic_module_name = module_name + DYNAMIC_MODULE_SUFFIX
33 exec( "import %s" % oringin_module_name )
34 origin_module = locals()[ oringin_module_name ]
35 origin_module_lines = inspect.getsourcelines( origin_module )[0]
36 origin_meshClass_lines = inspect.getsourcelines(origin_module.Mesh)[0]
37 origin_module_text = "".join( origin_module_lines )
38 origin_meshClass_text = "".join( origin_meshClass_lines )
40 exec( "import %s" % dynamic_module_name )
41 dynanmic_module = locals()[ dynamic_module_name ]
42 dynanmic_meshClass = dynanmic_module.Mesh
44 new_meshClass_lines = copy.copy(origin_meshClass_lines)
45 # remove end of class 'pass'
46 if new_meshClass_lines[-1].find("pass") > 0:
47 new_meshClass_lines.pop()
49 dynanmic_meshClass_methods = [x for x, y in dynanmic_meshClass.__dict__.items() if type(y) == FunctionType]
50 for method in dynanmic_meshClass_methods:
51 exec( "method_lines = inspect.getsourcelines(dynanmic_module.Mesh.%s)[0]" % method)
52 new_meshClass_lines+=locals()['method_lines']
54 new_meshClass_text = "".join( new_meshClass_lines )
56 f = open( output_file, "w" )
58 f.write( origin_module_text.replace( origin_meshClass_text, new_meshClass_text) )
60 except Exception as e:
66 if __name__ == "__main__":
68 parser = optparse.OptionParser(usage="%prog [options] modulename")
69 h = "Output file (smeshBuilder.py by default)"
70 parser.add_option("-o", "--output", dest="output",
71 action="store", default="smeshBuilder.py", metavar="file",
74 (options, args) = parser.parse_args()
76 if len( args ) < 1: sys.exit("Module name is not specified")
77 main( args[0], options.output )