2022-10-15 20:50:02 +08:00
|
|
|
|
|
2021-11-23 21:44:59 +08:00
|
|
|
|
from ruamel.yaml import YAML
|
|
|
|
|
|
from utils.manager import plugins_manager
|
|
|
|
|
|
from utils.utils import get_matchers
|
2022-10-15 20:50:02 +08:00
|
|
|
|
from services.log import logger
|
2022-11-21 20:43:41 +08:00
|
|
|
|
from configs.path_config import DATA_PATH
|
2021-11-23 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
import ujson as json
|
|
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_yaml = YAML(typ="safe")
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-21 20:43:41 +08:00
|
|
|
|
def init_plugins_data():
|
2021-11-23 21:44:59 +08:00
|
|
|
|
"""
|
|
|
|
|
|
初始化插件数据信息
|
|
|
|
|
|
"""
|
2022-11-21 20:43:41 +08:00
|
|
|
|
plugin2data_file = DATA_PATH / "manager" / "plugin_manager.json"
|
2021-11-23 21:44:59 +08:00
|
|
|
|
plugin2data_file.parent.mkdir(parents=True, exist_ok=True)
|
2022-11-21 20:43:41 +08:00
|
|
|
|
for matcher in get_matchers(True):
|
2022-07-31 17:30:29 +08:00
|
|
|
|
_plugin = matcher.plugin
|
2022-09-08 20:13:26 +08:00
|
|
|
|
if not _plugin:
|
|
|
|
|
|
continue
|
2022-07-31 17:30:29 +08:00
|
|
|
|
metadata = _plugin.metadata
|
2021-11-23 21:44:59 +08:00
|
|
|
|
try:
|
|
|
|
|
|
_module = _plugin.module
|
|
|
|
|
|
except AttributeError:
|
2022-11-21 20:43:41 +08:00
|
|
|
|
if matcher.plugin_name not in plugins_manager.keys():
|
2021-11-23 21:44:59 +08:00
|
|
|
|
plugins_manager.add_plugin_data(
|
2022-02-19 18:20:19 +08:00
|
|
|
|
matcher.plugin_name, matcher.plugin_name, error=True
|
2021-11-23 21:44:59 +08:00
|
|
|
|
)
|
|
|
|
|
|
else:
|
2022-11-21 20:43:41 +08:00
|
|
|
|
plugins_manager[matcher.plugin_name].error = True
|
2021-11-23 21:44:59 +08:00
|
|
|
|
else:
|
2022-10-15 20:50:02 +08:00
|
|
|
|
try:
|
|
|
|
|
|
plugin_version = None
|
|
|
|
|
|
if metadata:
|
|
|
|
|
|
plugin_version = metadata.extra.get("version")
|
2022-11-21 20:43:41 +08:00
|
|
|
|
if not plugin_version and hasattr(_module, "__plugin_version__"):
|
|
|
|
|
|
plugin_version = _module.__getattribute__("__plugin_version__")
|
2022-10-15 20:50:02 +08:00
|
|
|
|
if metadata:
|
|
|
|
|
|
plugin_name = metadata.name
|
|
|
|
|
|
else:
|
|
|
|
|
|
try:
|
|
|
|
|
|
plugin_name = _module.__getattribute__("__zx_plugin_name__")
|
|
|
|
|
|
except AttributeError:
|
|
|
|
|
|
plugin_name = matcher.plugin_name
|
|
|
|
|
|
plugin_author = None
|
|
|
|
|
|
if metadata:
|
|
|
|
|
|
plugin_author = metadata.extra.get('author')
|
2022-11-21 20:43:41 +08:00
|
|
|
|
if not plugin_author and hasattr(_module, "__plugin_author__"):
|
2022-10-15 20:50:02 +08:00
|
|
|
|
plugin_author = _module.__getattribute__("__plugin_author__")
|
|
|
|
|
|
if matcher.plugin_name in plugins_manager.keys():
|
2022-11-21 20:43:41 +08:00
|
|
|
|
plugins_manager[matcher.plugin_name].error = False
|
2022-10-15 20:50:02 +08:00
|
|
|
|
if matcher.plugin_name not in plugins_manager.keys():
|
|
|
|
|
|
plugins_manager.add_plugin_data(
|
|
|
|
|
|
matcher.plugin_name,
|
|
|
|
|
|
plugin_name=plugin_name,
|
|
|
|
|
|
author=plugin_author,
|
|
|
|
|
|
version=plugin_version,
|
|
|
|
|
|
)
|
|
|
|
|
|
# metadata不检测version
|
2022-11-21 20:43:41 +08:00
|
|
|
|
elif isinstance(plugin_version, str) or plugins_manager[matcher.plugin_name].version is None or (
|
2022-10-15 20:50:02 +08:00
|
|
|
|
plugin_version is not None
|
2022-11-21 20:43:41 +08:00
|
|
|
|
and plugin_version > float(plugins_manager[matcher.plugin_name].version)
|
2022-10-15 20:50:02 +08:00
|
|
|
|
):
|
2022-11-21 20:43:41 +08:00
|
|
|
|
plugins_manager[matcher.plugin_name].plugin_name = plugin_name
|
|
|
|
|
|
plugins_manager[matcher.plugin_name].author = plugin_author
|
|
|
|
|
|
plugins_manager[matcher.plugin_name].version = plugin_version
|
|
|
|
|
|
# if matcher.plugin_name in _data.keys():
|
|
|
|
|
|
# plugins_manager[matcher.plugin_name].error = _data[matcher.plugin_name]["error"]
|
|
|
|
|
|
# plugins_manager.set_module_data(
|
|
|
|
|
|
# matcher.plugin_name, "error", _data[matcher.plugin_name]["error"]
|
|
|
|
|
|
# )
|
|
|
|
|
|
# plugins_manager.set_module_data(
|
|
|
|
|
|
# matcher.plugin_name, "plugin_name", _data[matcher.plugin_name]["plugin_name"]
|
|
|
|
|
|
# )
|
2022-10-15 20:50:02 +08:00
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"插件数据 {matcher.plugin_name} 加载发生错误 {type(e)}:{e}")
|
2021-11-23 21:44:59 +08:00
|
|
|
|
plugins_manager.save()
|