2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2012-2016 CEA/DEN, EDF R&D, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #################################################################################
24 # File: collect_geom_methods.py
25 # Author: Roman NIKOLAEV, Open CASCADE S.A.S (roman.nikolaev@opencascade.com)
27 #################################################################################
29 # Extraction of the methods dynamically added by the Geometry
30 # module plug-in(s) to the geomBuilder class.
32 # This script is intended for internal usage - only
33 # for generatation of the extra developer documentation for
34 # the Geometry module plug-in(s).
37 # collect_geom_methods.py <plugin_name>
39 # <plugin_name> is a name of the plug-in module
42 # - the script is supposed to be run in correct environment
43 # i.e. PYTHONPATH, GEOM_PluginsList and other important
44 # variables are set properly; otherwise the script will fail.
46 ################################################################################
51 def generate(plugin_name, output):
52 plugin_module_name = plugin_name + "Builder"
53 plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name)
54 import_str = "from salome.%s import %s" % (plugin_name, plugin_module_name)
55 execLine = "from salome.%s import %s\nimport %s\nmod = %s" % (plugin_name, plugin_module_name,plugin_module,plugin_module)
58 exec( execLine , namespace)
60 for attr in dir( namespace["mod"] ):
61 if attr.startswith( '_' ): continue # skip an internal methods
62 item = getattr( namespace["mod"], attr )
63 if type( item ).__name__ == 'function':
64 if item not in functions:
65 functions.append( item )
70 for function in functions:
71 comments = inspect.getcomments(function)
73 comments = comments.strip().split("\n")
74 comments = "\t" + "\n\t".join(comments)
75 output.append(comments)
77 sources = inspect.getsource(function)
78 if sources is not None:
79 sources_list = sources.split("\n")
82 for item in sources_list:
93 sources_new_list.append(item)
96 sources = "\n".join(sources_new_list)
97 sources = "\t" + sources.replace("\n", "\n\t")
98 output.append(sources)
104 if __name__ == "__main__":
106 parser = optparse.OptionParser(usage="%prog [options] plugin")
107 h = "Output file (geomBuilder.py by default)"
108 parser.add_option("-o", "--output", dest="output",
109 action="store", default=None, metavar="file",
111 h = "If this option is True, dummy help for geomBuiler class is added. "
112 h += "This option should be False (default) when building documentation for Geometry module "
113 h += "and True when building documentation for Geometry module plug-ins."
114 parser.add_option("-d", "--dummy-geom-help", dest="dummygeomhelp",
115 action="store_true", default=False,
117 (options, args) = parser.parse_args()
118 if len( args ) < 1: sys.exit("Plugin name is not specified")
120 f = open(options.output, "w")
123 plugins_names = " ".join(args) + " plugins"
125 plugins_names = args[0] + " plugin"
129 if options.dummygeomhelp:
130 output.append( "## @package geomBuilder" )
131 output.append( "# Documentation of the methods dynamically added by the " + plugins_names + " to the @b %geomBuilder class." )
132 # Add dummy Geometry help
133 # This is supposed to be done when generating documentation for Geometry module plug-ins
134 output.append( "# @note The documentation below does not provide complete description of class @b %geomBuilder" )
135 output.append( "# from @b geomBuilder package. This documentation provides only information about" )
136 output.append( "# the methods dynamically added to the %geomBuilder class by the " + plugins_names + "." )
137 output.append( "# For more details on the %geomBuilder class, please refer to the SALOME %Geometry module" )
138 output.append( "# documentation." )
141 # Extend documentation for geomBuilder class with information about dynamically added methods.
142 # This is supposed to be done only when building documentation for Geometry module
143 output.append( "## @package geomBuilder" )
144 output.append( "# @note Some methods are dynamically added to the @b %geomBuilder class in runtime by the" )
145 output.append( "# plug-in modules. If you fail to find help on some methods in the documentation of Geometry module, " )
146 output.append( "# try to look into the documentation for the Geometry module plug-ins." )
148 output.append("class geomBuilder():")
151 generate( arg, output )
154 for line in output: f.write( line + "\n" )