Python 3 - Update of previous commit

This commit is contained in:
Gilles DAVID 2017-05-29 14:36:10 +02:00
parent 6f199e6cff
commit 9ddbfddd27

View File

@ -48,26 +48,26 @@ import sys
import inspect import inspect
def generate(plugin_name, output): def generate(plugin_name, output):
import types 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_name = plugin_name + "Builder"
plugin_module = "salome.%s.%s" % (plugin_name, plugin_module_name) plugin_module = "salome.{}.{}".format(plugin_name, plugin_module_name)
import_str = "from salome.%s import %s" % (plugin_name, plugin_module_name) import_str = "from salome.{} import {}".format(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.{} 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
item = getattr(namespace["mod"], attr)
if isinstance(item, types.FunctionType):
if item not in functions:
functions.append(item)
pass
pass
pass
if functions:
for function in functions:
comments = inspect.getcomments(function) comments = inspect.getcomments(function)
if comments: if comments:
comments = comments.strip().split("\n") comments = comments.strip().split("\n")
@ -99,7 +99,6 @@ def generate(plugin_name, output):
pass pass
pass pass
pass pass
pass
if __name__ == "__main__": if __name__ == "__main__":
import argparse import argparse
@ -148,4 +147,3 @@ if __name__ == "__main__":
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))