__init__.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. ]
  17. if MOD_LOAD or MOD_NOLOAD:
  18. to_Load = MOD_LOAD
  19. if to_Load:
  20. if not all(
  21. any(mod == module_name for module_name in all_modules)
  22. for mod in to_Load
  23. ):
  24. log.error("Invalid Module name!")
  25. quit(1)
  26. else:
  27. to_Load = all_modules
  28. if MOD_NOLOAD:
  29. log.info("No load: {}".format(MOD_NOLOAD))
  30. return [item for item in to_Load if item not in MOD_NOLOAD]
  31. return to_Load
  32. return all_modules
  33. importlib.import_module("wbb.modules.__main__")
  34. ALL_MODULES = sorted(__list_all_modules())
  35. log.info("Modules loaded: %s", str(ALL_MODULES))
  36. __all__ = ALL_MODULES + ["ALL_MODULES"]