-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# Copyright (C) 2012-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+#!/usr/bin/env python3
+# Copyright (C) 2012-2016 CEA/DEN, EDF R&D, OPEN CASCADE
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
import inspect
def generate(plugin_name, output):
- plugin_module_name = plugin_name + "Builder"
- plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name)
- import_str = "from salome.%s import %s" % (plugin_name, plugin_module_name)
- exec( import_str )
- exec( "import %s" % plugin_module )
- exec( "mod = %s" % plugin_module )
- functions = []
- for attr in dir( mod ):
- if attr.startswith( '_' ): continue # skip an internal methods
- item = getattr( mod, attr )
- if type( item ).__name__ == 'function':
- if item not in functions:
- functions.append( item )
- pass
- pass
- pass
- if functions:
- for function in functions:
- comments = inspect.getcomments(function)
- if comments:
- comments = comments.strip().split("\n")
- comments = "\t" + "\n\t".join(comments)
- output.append(comments)
- pass
- sources = inspect.getsource(function)
- if sources is not None:
- sources_list = sources.split("\n")
- sources_new_list = []
- found = False
- for item in sources_list:
- if '"""' in item:
- if found == True:
- found = False
- continue
- else:
- found = True
- continue
- pass
- pass
- if found == False :
- sources_new_list.append(item)
+ def get_functions(amodule):
+ for attr in dir(amodule):
+ if attr.startswith( '_' ): continue # skip an internal methods
+ item = getattr(amodule, attr)
+ if inspect.isfunction(item):
+ yield item
+ pass
+ pass
+
+ plugin_module_name = plugin_name + "Builder"
+ plugin_module = "salome.{}.{}".format(plugin_name, plugin_module_name)
+ import_str = "from salome.{} import {}".format(plugin_name, plugin_module_name)
+ execLine = "from salome.{} import {}\n" \
+ "import {}\n" \
+ "mod = {}".format(plugin_name, plugin_module_name, plugin_module, plugin_module)
+ print(execLine)
+ namespace = {}
+ exec(execLine , namespace)
+
+ for function in get_functions(namespace["mod"]):
+ comments = inspect.getcomments(function)
+ if comments:
+ comments = comments.strip().split("\n")
+ comments = "\t" + "\n\t".join(comments)
+ output.append(comments)
+ pass
+ sources = inspect.getsource(function)
+ if sources is not None:
+ sources_list = sources.split("\n")
+ sources_new_list = []
+ found = False
+ for item in sources_list:
+ if '"""' in item:
+ if found == True:
+ found = False
+ continue
+ else:
+ found = True
+ continue
pass
+ pass
+ if found == False:
+ sources_new_list.append(item)
pass
- sources = "\n".join(sources_new_list)
- sources = "\t" + sources.replace("\n", "\n\t")
- output.append(sources)
pass
+ sources = "\n".join(sources_new_list)
+ sources = "\t" + sources.replace("\n", "\n\t")
+ output.append(sources)
pass
pass
pass
if __name__ == "__main__":
- import optparse
- parser = optparse.OptionParser(usage="%prog [options] plugin")
+ import argparse
+ parser = argparse.ArgumentParser()
h = "Output file (geomBuilder.py by default)"
- parser.add_option("-o", "--output", dest="output",
- action="store", default=None, metavar="file",
- help=h)
+ parser.add_argument("-o", "--output", dest="output",
+ action="store", default='geomBuilder.py', metavar="file",
+ help=h)
h = "If this option is True, dummy help for geomBuiler class is added. "
h += "This option should be False (default) when building documentation for Geometry module "
h += "and True when building documentation for Geometry module plug-ins."
- parser.add_option("-d", "--dummy-geom-help", dest="dummygeomhelp",
- action="store_true", default=False,
- help=h)
- (options, args) = parser.parse_args()
- if len( args ) < 1: sys.exit("Plugin name is not specified")
+ parser.add_argument("-d", "--dummy-geom-help", dest="dummygeomhelp",
+ action="store_true", default=False,
+ help=h)
+ parser.add_argument("plugin", nargs='+', help='Name of plugin')
+ args = parser.parse_args()
- f = open(options.output, "w")
-
+ plugins_names = " ".join(args.plugin) + 'plugin'
+ if len(args.plugin) > 1:
+ plugins_names += 's'
output = []
- if options.dummygeomhelp:
- output.append( "## @package geomBuilder" )
- output.append( "# Documentation of the methods dynamically added by the " + plugin_name + " Geometry plug-in to the geomBuilder class." )
+ if args.dummygeomhelp:
+ output.append("## @package geomBuilder")
+ output.append("# Documentation of the methods dynamically added by the " + plugins_names + " to the @b %geomBuilder class.")
# Add dummy Geometry help
# This is supposed to be done when generating documentation for Geometry module plug-ins
- output.append( "# @note The documentation below does not provide complete description of class @b %geomBuilder" )
- output.append( "# from @b geomBuilder package. This documentation provides only information about" )
- output.append( "# the methods dynamically added to the %geomBuilder class by the " + plugin_name + " plugin" )
- output.append( "# For more details on the %geomBuilder class, please refer to the SALOME %Geometry module" )
- output.append( "# documentation." )
+ output.append("# @note The documentation below does not provide complete description of class @b %geomBuilder")
+ output.append("# from @b geomBuilder package. This documentation provides only information about")
+ output.append("# the methods dynamically added to the %geomBuilder class by the " + plugins_names + ".")
+ output.append("# For more details on the %geomBuilder class, please refer to the SALOME %Geometry module")
+ output.append("# documentation.")
pass
else:
# Extend documentation for geomBuilder class with information about dynamically added methods.
# This is supposed to be done only when building documentation for Geometry module
- output.append( "## @package geomBuilder" )
- output.append( "# @note Some methods are dynamically added to the @b %geomBuilder class in runtime by the" )
- output.append( "# plug-in modules. If you fail to find help on some methods in the documentation of Geometry module, " )
- output.append( "# try to look into the documentation for the Geometry module plug-ins." )
+ output.append("## @package geomBuilder")
+ output.append("# @note Some methods are dynamically added to the @b %geomBuilder class in runtime by the")
+ output.append("# plug-in modules. If you fail to find help on some methods in the documentation of Geometry module, ")
+ output.append("# try to look into the documentation for the Geometry module plug-ins.")
pass
output.append("class geomBuilder():")
- for arg in args:
- generate( arg, output )
- pass
+ for plugin_name in args.plugin:
+ generate( plugin_name, output )
+ pass
- for line in output: f.write( line + "\n" )
- f.close()
+ with open(args.output, "w", encoding='utf8') as f:
+ f.write('\n'.join(output))