From: Gilles DAVID Date: Wed, 24 May 2017 08:06:22 +0000 (+0200) Subject: Python 3 porting X-Git-Tag: V9_0_0~4^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6f199e6cff2ee36d367767d1bf6db694a6e02773;p=modules%2Fgeom.git Python 3 porting optparse replaced by argparse --- diff --git a/doc/salome/gui/GEOM/collect_geom_methods.py b/doc/salome/gui/GEOM/collect_geom_methods.py index 71a11da55..7bc6086d9 100644 --- a/doc/salome/gui/GEOM/collect_geom_methods.py +++ b/doc/salome/gui/GEOM/collect_geom_methods.py @@ -1,5 +1,4 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/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 @@ -49,20 +48,21 @@ import sys import inspect def generate(plugin_name, output): + import types 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) - execLine = "from salome.%s import %s\nimport %s\nmod = %s" % (plugin_name, plugin_module_name,plugin_module,plugin_module) + execLine = "from salome.%s import %s\nimport %s\nmod = %s" % (plugin_name, plugin_module_name, plugin_module, plugin_module) print(execLine) namespace = {} - exec( execLine , namespace) + exec(execLine , namespace) functions = [] - for attr in dir( namespace["mod"] ): - if attr.startswith( '_' ): continue # skip an internal methods - item = getattr( namespace["mod"], attr ) - if type( item ).__name__ == 'function': - if item not in functions: - functions.append( item ) + for attr in dir(namespace["mod"]): + if attr.startswith( '_' ): continue # skip an internal methods + item = getattr(namespace["mod"], attr) + if isinstance(item, types.FunctionType): + if item not in functions: + functions.append(item) pass pass pass @@ -89,7 +89,7 @@ def generate(plugin_name, output): continue pass pass - if found == False : + if found == False: sources_new_list.append(item) pass pass @@ -102,54 +102,50 @@ def generate(plugin_name, output): 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") - - if len(args) > 1: - plugins_names = " ".join(args) + " plugins" - elif len(args) == 1: - plugins_names = args[0] + " plugin" - else: - plugins_names = "" + 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 " + plugins_names + " to the @b %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 " + plugins_names + "." ) - 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 ) + 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)) +