添加插件管理功能,显示插件的相关信息。
This commit is contained in:
@@ -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"PluginManager:self.plugins: {self.plugins}")
|
||||
self.LOG.info(f"PluginManager:self.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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user