Commit 825c7853 authored by Andreas Dedner's avatar Andreas Dedner

added a get method in the create module returning the generating function

parent 1a67dbde
Pipeline #14733 passed with stage
in 7 minutes and 8 seconds
......@@ -19,6 +19,7 @@ prefix = package.__name__ + "."
subpackages = []
logMsg = "Importing create registries from [ "
# first import all 'dune' subpackages and collect the 'registry' dicts
for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
if not ispkg:
continue
......@@ -32,6 +33,7 @@ for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
logger.debug('failed to import ' + modname + ': ' + str(e) + '.')
continue
# read the registry
try:
moduleRegistry = module.registry.items()
logMsg = logMsg + modname + " "
......@@ -39,6 +41,7 @@ for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
logger.debug('module ' + modname + ' does not provide a registry.')
continue
# combine all registries
for obj, registry in moduleRegistry:
objmap = dict()
try:
......@@ -52,15 +55,43 @@ for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
objmap[key.upper().lower()] = [value,modname]
# the grids registry also provide view -
# so we will add them to the # grid to the there as well
# so we will add them to the 'view' entry
_create_map.setdefault("view",{}).update(_create_map["grid"])
logMsg = logMsg + "]"
logger.info(logMsg)
############################################################################
def get(category=None,entry=None):
entry_ = _create_map.get(category,None)
if entry_ is None:
if category is not None:
print("category '",category,"' not valid,",end="")
print("available categories are:",
','.join(k for k in _create_map))
return
if entry is None:
print("available entries for this category are:")
for k,e in entry_.items():
n = e[0].__module__.split(".")
if n[-1][0]=="_":
del n[-1]
print(k,"\t\t\t function'"+e[0].__name__+"' from '"+'.'.join(m for m in n)+"'")
else:
entry__ = entry_.get(entry,None)
if entry__ is None:
print("available entries are:",
','.join(k for k in entry_))
return
return entry__[0]
############################################################################
## the second part is for the 'load' method
# a helper class
class Empty:
pass
def signatureDict(func):
# get signature from func, we simply fill a dictonary with the name of
# all non var argument of the function as key and containing a either
......@@ -150,6 +181,8 @@ def creatorCall(self, key, *args, **kwargs):
assert set(kwargs) == usedKeys, "some provided named parameters where not used"
return instance
##########################################################################
## for each 'registry' entry add a function to this module
for obj, registry in _create_map.items():
# docs = "\n".join(k+" from "+v[1] for k,v in registry.items())
docs_format = "{:<25}" * (2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment