PagerMaid-Pyro/pagermaid/modules/__init__.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.4 KiB
Python
Raw Permalink Normal View History

2022-05-23 12:40:30 +00:00
""" PagerMaid module and plugin init. """
from glob import glob
from os import getcwd, makedirs, sep
from os.path import dirname, basename, isfile, exists
from pagermaid.utils import lang, logs
2022-05-23 12:40:30 +00:00
def __list_modules():
2022-06-20 13:55:14 +00:00
module_paths = glob(f"{dirname(__file__)}{sep}*.py")
return [
2022-05-23 12:40:30 +00:00
basename(file)[:-3]
for file in module_paths
2023-03-12 03:56:01 +00:00
if isfile(file) and file.endswith(".py") and not file.endswith("__init__.py")
2022-05-23 12:40:30 +00:00
]
def __list_plugins():
plugin_paths = glob(f"{getcwd()}{sep}plugins" + f"{sep}*.py")
if not exists(f"{getcwd()}{sep}plugins"):
makedirs(f"{getcwd()}{sep}plugins")
2022-06-20 13:55:14 +00:00
return [
2022-05-23 12:40:30 +00:00
basename(file)[:-3]
for file in plugin_paths
2023-03-12 03:56:01 +00:00
if isfile(file) and file.endswith(".py") and not file.endswith("__init__.py")
2022-05-23 12:40:30 +00:00
]
2023-03-12 03:56:01 +00:00
module_list_string = "".join(f"{module}, " for module in sorted(__list_modules()))
2022-05-23 12:40:30 +00:00
module_list_string = module_list_string[:-2]
2023-03-12 03:56:01 +00:00
plugin_list_string = "".join(f"{plugin}, " for plugin in sorted(__list_plugins()))
2022-05-23 12:40:30 +00:00
plugin_list_string = plugin_list_string[:-2]
module_list = sorted(__list_modules())
plugin_list = sorted(__list_plugins())
logs.info(f"{lang('modules_init_loading_modules')}: {module_list_string}")
if len(plugin_list) > 0:
logs.info(f"{lang('modules_init_loading_plugins')}: {plugin_list_string}")
__all__ = __list_modules() + ["module_list"] + __list_plugins() + ["plugin_list"]