mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-24 06:30:34 +05:00
Python 3 - Update of previous commit
This commit is contained in:
parent
6f199e6cff
commit
9ddbfddd27
@ -48,55 +48,54 @@ import sys
|
|||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
def generate(plugin_name, output):
|
def generate(plugin_name, output):
|
||||||
import types
|
def get_functions(amodule):
|
||||||
plugin_module_name = plugin_name + "Builder"
|
for attr in dir(amodule):
|
||||||
plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name)
|
if attr.startswith( '_' ): continue # skip an internal methods
|
||||||
import_str = "from salome.%s import %s" % (plugin_name, plugin_module_name)
|
item = getattr(amodule, attr)
|
||||||
execLine = "from salome.%s import %s\nimport %s\nmod = %s" % (plugin_name, plugin_module_name, plugin_module, plugin_module)
|
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)
|
print(execLine)
|
||||||
namespace = {}
|
namespace = {}
|
||||||
exec(execLine , namespace)
|
exec(execLine , namespace)
|
||||||
functions = []
|
|
||||||
for attr in dir(namespace["mod"]):
|
for function in get_functions(namespace["mod"]):
|
||||||
if attr.startswith( '_' ): continue # skip an internal methods
|
comments = inspect.getcomments(function)
|
||||||
item = getattr(namespace["mod"], attr)
|
if comments:
|
||||||
if isinstance(item, types.FunctionType):
|
comments = comments.strip().split("\n")
|
||||||
if item not in functions:
|
comments = "\t" + "\n\t".join(comments)
|
||||||
functions.append(item)
|
output.append(comments)
|
||||||
pass
|
pass
|
||||||
pass
|
sources = inspect.getsource(function)
|
||||||
pass
|
if sources is not None:
|
||||||
if functions:
|
sources_list = sources.split("\n")
|
||||||
for function in functions:
|
sources_new_list = []
|
||||||
comments = inspect.getcomments(function)
|
found = False
|
||||||
if comments:
|
for item in sources_list:
|
||||||
comments = comments.strip().split("\n")
|
if '"""' in item:
|
||||||
comments = "\t" + "\n\t".join(comments)
|
if found == True:
|
||||||
output.append(comments)
|
found = False
|
||||||
pass
|
continue
|
||||||
sources = inspect.getsource(function)
|
else:
|
||||||
if sources is not None:
|
found = True
|
||||||
sources_list = sources.split("\n")
|
continue
|
||||||
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
|
pass
|
||||||
|
pass
|
||||||
|
if found == False:
|
||||||
|
sources_new_list.append(item)
|
||||||
pass
|
pass
|
||||||
sources = "\n".join(sources_new_list)
|
|
||||||
sources = "\t" + sources.replace("\n", "\n\t")
|
|
||||||
output.append(sources)
|
|
||||||
pass
|
pass
|
||||||
|
sources = "\n".join(sources_new_list)
|
||||||
|
sources = "\t" + sources.replace("\n", "\n\t")
|
||||||
|
output.append(sources)
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
pass
|
pass
|
||||||
@ -144,8 +143,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
for plugin_name in args.plugin:
|
for plugin_name in args.plugin:
|
||||||
generate( plugin_name, output )
|
generate( plugin_name, output )
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with open(args.output, "w", encoding='utf8') as f:
|
with open(args.output, "w", encoding='utf8') as f:
|
||||||
f.write('\n'.join(output))
|
f.write('\n'.join(output))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user