__init__.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 folder for the * in __main__ to work.
  7. mod_paths = glob.glob(dirname(__file__) + "/*.py")
  8. all_modules = [
  9. basename(f)[:-3]
  10. for f in mod_paths
  11. if isfile(f)
  12. and f.endswith(".py")
  13. and not f.endswith("__init__.py")
  14. and not f.endswith("__main__.py")
  15. ]
  16. if MOD_LOAD or MOD_NOLOAD:
  17. to_Load = MOD_LOAD
  18. if to_Load:
  19. if not all(
  20. any(mod == module_name for module_name in all_modules)
  21. for mod in to_Load
  22. ):
  23. log.error("Invalid Module name!")
  24. quit(1)
  25. else:
  26. to_Load = all_modules
  27. if MOD_NOLOAD:
  28. log.info("No load: {}".format(MOD_NOLOAD))
  29. return [item for item in to_Load if item not in MOD_NOLOAD]
  30. return to_Load
  31. return all_modules
  32. importlib.import_module("wbb.modules.__main__")
  33. ALL_MODULES = sorted(__list_all_modules())
  34. log.info("Modules loaded: %s", str(ALL_MODULES))
  35. __all__ = ALL_MODULES + ["ALL_MODULES"]