Commit 101f578a authored by Nathan/Eilisha Shiraini's avatar Nathan/Eilisha Shiraini
Browse files

Implemented auto detection of code builder modules

parent 0ca1209c
import os
import sys
import importlib
EXCLUDE_MODULES = [
"imgen",
]
def _findModules(location = '.'):
exts = [
'.py',
'.pyd' if sys.platform.startswith('win') else '.so',
]
elements = os.scandir(location)
for item in elements:
if item.name.startswith('_') or item.name in EXCLUDE_MODULES:
continue
if item.is_file() and not any(item.name.endswith(i) for i in exts):
continue
if item.is_dir() and not os.access(os.path.join(item.path, '__init__.py'), os.R_OK):
continue
filename = os.path.splitext(item.name)[0]
if '.' in filename:
continue
yield filename
def _findBuilders(location = '.'):
for modname in _findModules(location):
if __name__ == '__main__':
module = importlib.import_module(modname)
else:
module = importlib.import_module('.' + modname, __name__)
try:
builder = module.Builder
params = module.IMGEN_PARAMS
name = module.NAME
except AttributeError:
continue
yield {
'id' : modname,
'name' : name,
'builder' : builder,
'params' : params,
'module' : module,
}
BUILDERS = {mod['id'] : mod for mod in _findBuilders(os.path.dirname(__file__))}
def listBuilders():
return '\n'.join("{0[id]} : {0[name]} {0[builder]!r}".format(m) for m in BUILDERS.values())
if __name__ == '__main__':
print(listBuilders())
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