mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-04-24 08:02:03 +05:00
Python 3 porting
optparse replaced by argparse
This commit is contained in:
parent
d6d9a9dab6
commit
6f199e6cff
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2012-2016 CEA/DEN, EDF R&D, OPEN CASCADE
|
# Copyright (C) 2012-2016 CEA/DEN, EDF R&D, OPEN CASCADE
|
||||||
#
|
#
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@ -49,6 +48,7 @@ import sys
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
def generate(plugin_name, output):
|
def generate(plugin_name, output):
|
||||||
|
import types
|
||||||
plugin_module_name = plugin_name + "Builder"
|
plugin_module_name = plugin_name + "Builder"
|
||||||
plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name)
|
plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name)
|
||||||
import_str = "from salome.%s import %s" % (plugin_name, plugin_module_name)
|
import_str = "from salome.%s import %s" % (plugin_name, plugin_module_name)
|
||||||
@ -60,7 +60,7 @@ def generate(plugin_name, output):
|
|||||||
for attr in dir(namespace["mod"]):
|
for attr in dir(namespace["mod"]):
|
||||||
if attr.startswith( '_' ): continue # skip an internal methods
|
if attr.startswith( '_' ): continue # skip an internal methods
|
||||||
item = getattr(namespace["mod"], attr)
|
item = getattr(namespace["mod"], attr)
|
||||||
if type( item ).__name__ == 'function':
|
if isinstance(item, types.FunctionType):
|
||||||
if item not in functions:
|
if item not in functions:
|
||||||
functions.append(item)
|
functions.append(item)
|
||||||
pass
|
pass
|
||||||
@ -102,31 +102,26 @@ def generate(plugin_name, output):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import optparse
|
import argparse
|
||||||
parser = optparse.OptionParser(usage="%prog [options] plugin")
|
parser = argparse.ArgumentParser()
|
||||||
h = "Output file (geomBuilder.py by default)"
|
h = "Output file (geomBuilder.py by default)"
|
||||||
parser.add_option("-o", "--output", dest="output",
|
parser.add_argument("-o", "--output", dest="output",
|
||||||
action="store", default=None, metavar="file",
|
action="store", default='geomBuilder.py', metavar="file",
|
||||||
help=h)
|
help=h)
|
||||||
h = "If this option is True, dummy help for geomBuiler class is added. "
|
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 += "This option should be False (default) when building documentation for Geometry module "
|
||||||
h += "and True when building documentation for Geometry module plug-ins."
|
h += "and True when building documentation for Geometry module plug-ins."
|
||||||
parser.add_option("-d", "--dummy-geom-help", dest="dummygeomhelp",
|
parser.add_argument("-d", "--dummy-geom-help", dest="dummygeomhelp",
|
||||||
action="store_true", default=False,
|
action="store_true", default=False,
|
||||||
help=h)
|
help=h)
|
||||||
(options, args) = parser.parse_args()
|
parser.add_argument("plugin", nargs='+', help='Name of plugin')
|
||||||
if len( args ) < 1: sys.exit("Plugin name is not specified")
|
args = parser.parse_args()
|
||||||
|
|
||||||
f = open(options.output, "w")
|
plugins_names = " ".join(args.plugin) + 'plugin'
|
||||||
|
if len(args.plugin) > 1:
|
||||||
if len(args) > 1:
|
plugins_names += 's'
|
||||||
plugins_names = " ".join(args) + " plugins"
|
|
||||||
elif len(args) == 1:
|
|
||||||
plugins_names = args[0] + " plugin"
|
|
||||||
else:
|
|
||||||
plugins_names = ""
|
|
||||||
output = []
|
output = []
|
||||||
if options.dummygeomhelp:
|
if args.dummygeomhelp:
|
||||||
output.append("## @package geomBuilder")
|
output.append("## @package geomBuilder")
|
||||||
output.append("# Documentation of the methods dynamically added by the " + plugins_names + " to the @b %geomBuilder class.")
|
output.append("# Documentation of the methods dynamically added by the " + plugins_names + " to the @b %geomBuilder class.")
|
||||||
# Add dummy Geometry help
|
# Add dummy Geometry help
|
||||||
@ -147,9 +142,10 @@ if __name__ == "__main__":
|
|||||||
pass
|
pass
|
||||||
output.append("class geomBuilder():")
|
output.append("class geomBuilder():")
|
||||||
|
|
||||||
for arg in args:
|
for plugin_name in args.plugin:
|
||||||
generate( arg, output )
|
generate( plugin_name, output )
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for line in output: f.write( line + "\n" )
|
with open(args.output, "w", encoding='utf8') as f:
|
||||||
f.close()
|
f.write('\n'.join(output))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user