添加插件管理功能,显示插件的相关信息。

This commit is contained in:
liuwei
2025-04-11 14:41:19 +08:00
parent 4a860196e9
commit 84a3a9679e

View File

@@ -101,6 +101,10 @@ class PluginManager:
"""
plugin_modules = self.discover_plugins()
loaded_plugins = []
failed_plugins = []
# 记录开始加载的插件列表
self.LOG.info(f"PluginManager开始加载插件列表: {plugin_modules}")
for plugin_name in plugin_modules:
try:
@@ -109,13 +113,45 @@ class PluginManager:
loaded_plugins.append(plugin_name)
# 自动启动插件
self.start_plugin(plugin.name)
else:
failed_plugins.append(plugin_name)
except Exception as e:
self.LOG.error(f"PluginManager加载插件 {plugin_name} 时发生错误: {str(e)}", exc_info=True)
failed_plugins.append(plugin_name)
# self.LOG.info(f"PluginManager成功加载插件: {loaded_plugins}")
# self.LOG.info(f"PluginManagerself.plugins: {self.plugins}")
self.LOG.info(f"PluginManagerself.module_to_plugin: {self.module_to_plugin}")
# 验证所有已加载插件的模块映射
for name, plugin in self.plugins.items():
try:
module_name = plugin.__class__.__module__.split('.')[-2]
if module_name not in self.module_to_plugin:
self.module_to_plugin[module_name] = name
self.LOG.info(f"PluginManager补充缺失的模块映射 {module_name} -> {name}")
except (IndexError, AttributeError) as e:
self.LOG.warning(f"PluginManager获取插件 {name} 的模块名时出错: {e}")
# 使用插件目录名作为备选模块名
folder_name = name.lower().replace(' ', '_')
if folder_name not in self.module_to_plugin:
self.module_to_plugin[folder_name] = name
self.LOG.info(f"PluginManager使用目录名作为模块映射 {folder_name} -> {name}")
# 检查是否有重复或无效的映射
invalid_mappings = []
for module_name, plugin_name in self.module_to_plugin.items():
if plugin_name not in self.plugins:
invalid_mappings.append(module_name)
self.LOG.warning(f"PluginManager发现无效的模块映射 {module_name} -> {plugin_name}")
# 清理无效的映射
for module_name in invalid_mappings:
del self.module_to_plugin[module_name]
self.LOG.info(f"PluginManager清理无效的模块映射 {module_name}")
# 记录最终状态
self.LOG.info(f"PluginManager加载成功的插件: {loaded_plugins}")
if failed_plugins:
self.LOG.warning(f"PluginManager加载失败的插件: {failed_plugins}")
self.LOG.info(f"PluginManager当前已加载的插件实例: {list(self.plugins.keys())}")
self.LOG.info(f"PluginManager最终的模块映射关系: {self.module_to_plugin}")
return self.plugins