__init__.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import glob
  2. import importlib
  3. import sys
  4. from os.path import dirname, basename, isfile
  5. from wbb import MOD_LOAD, MOD_NOLOAD, log
  6. def __list_all_modules():
  7. # This generates a list of modules in this
  8. # folder for the * in __main__ to work.
  9. mod_paths = glob.glob(dirname(__file__) + "/*.py")
  10. all_modules = [
  11. basename(f)[:-3]
  12. for f in mod_paths
  13. if isfile(f)
  14. and f.endswith(".py")
  15. and not f.endswith("__init__.py")
  16. and not f.endswith("__main__.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. sys.exit()
  27. else:
  28. to_load = all_modules
  29. if MOD_NOLOAD:
  30. log.info("No load: %s", 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"]