__init__.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import importlib
  2. from wbb import MOD_LOAD, MOD_NOLOAD, log
  3. def __list_all_modules():
  4. from os.path import dirname, basename, isfile
  5. import glob
  6. # This generates a list of modules in this
  7. # folder for the * in __main__ to work.
  8. mod_paths = glob.glob(dirname(__file__) + "/*.py")
  9. all_modules = [
  10. basename(f)[:-3]
  11. for f in mod_paths
  12. if isfile(f)
  13. and f.endswith(".py")
  14. and not f.endswith("__init__.py")
  15. and not f.endswith("__main__.py")
  16. and not f.endswith("_DISABLED.py")
  17. ]
  18. if MOD_LOAD or MOD_NOLOAD:
  19. to_Load = MOD_LOAD
  20. if to_Load:
  21. if not all(
  22. any(mod == module_name for module_name in all_modules)
  23. for mod in to_Load
  24. ):
  25. log.error("Invalid Module name!")
  26. quit(1)
  27. else:
  28. to_Load = all_modules
  29. if MOD_NOLOAD:
  30. log.info("No load: {}".format(MOD_NOLOAD))
  31. return [item for item in to_Load if item not in MOD_NOLOAD]
  32. return to_Load
  33. return all_modules
  34. importlib.import_module("wbb.modules.__main__")
  35. ALL_MODULES = sorted(__list_all_modules())
  36. log.info("Modules loaded: %s", str(ALL_MODULES))
  37. __all__ = ALL_MODULES + ["ALL_MODULES"]