__init__.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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
  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. sys.exit()
  26. else:
  27. to_load = all_modules
  28. if 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. __all__ = ALL_MODULES + ["ALL_MODULES"]