mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-24 06:20:33 +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
|
||||
# -*- 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,6 +48,7 @@ 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)
|
||||
@ -60,7 +60,7 @@ def generate(plugin_name, output):
|
||||
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 isinstance(item, types.FunctionType):
|
||||
if item not in functions:
|
||||
functions.append(item)
|
||||
pass
|
||||
@ -102,31 +102,26 @@ 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",
|
||||
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",
|
||||
parser.add_argument("-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("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:
|
||||
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
|
||||
@ -147,9 +142,10 @@ if __name__ == "__main__":
|
||||
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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user