fix module
This commit is contained in:
parent
9451f79cb0
commit
7248ce3105
@ -47,14 +47,17 @@ class ChainBase(AbstractSingleton, metaclass=Singleton):
|
||||
for module in modules:
|
||||
try:
|
||||
if is_result_empty(result):
|
||||
# 返回None,第一次执行或者需继续执行下一模块
|
||||
result = getattr(module, method)(*args, **kwargs)
|
||||
else:
|
||||
if isinstance(result, tuple):
|
||||
temp = getattr(module, method)(*result)
|
||||
if isinstance(result, list):
|
||||
# 返回为列表,有多个模块运行结果时进行合并(不能多个模块同时运行的需要通过开关控制)
|
||||
temp = getattr(module, method)(*args, **kwargs)
|
||||
if isinstance(temp, list):
|
||||
result.extend(temp)
|
||||
else:
|
||||
temp = getattr(module, method)(result)
|
||||
if temp:
|
||||
result = temp
|
||||
# 返回结果非列表也非空,则执行一次后跳出
|
||||
break
|
||||
except Exception as err:
|
||||
logger.error(f"运行模块 {method} 出错:{module.__class__.__name__} - {err}\n{traceback.print_exc()}")
|
||||
return result
|
||||
|
@ -38,6 +38,7 @@ class ModuleManager(metaclass=Singleton):
|
||||
_module = module()
|
||||
# 初始化模块
|
||||
if self.check_setting(_module.init_setting()):
|
||||
# 通过模板开关控制加载
|
||||
_module.init_module()
|
||||
self._running_modules[module_id] = _module
|
||||
logger.info(f"Moudle Loaded:{module_id}")
|
||||
@ -53,20 +54,20 @@ class ModuleManager(metaclass=Singleton):
|
||||
@staticmethod
|
||||
def check_setting(setting: Optional[tuple]) -> bool:
|
||||
"""
|
||||
检查开关是否己打开
|
||||
检查开关是否己打开,开关使用,分隔多个值,符合其中即代表开启
|
||||
"""
|
||||
if not setting:
|
||||
return True
|
||||
switch, value = setting
|
||||
if getattr(settings, switch) and value is True:
|
||||
return True
|
||||
if getattr(settings, switch) == value:
|
||||
if value in getattr(settings, switch):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_modules(self, method: str) -> Generator:
|
||||
"""
|
||||
获取模块列表
|
||||
获取实现了同一方法的模块列表
|
||||
"""
|
||||
if not self._running_modules:
|
||||
return []
|
||||
|
@ -19,6 +19,7 @@ class _ModuleBase(metaclass=ABCMeta):
|
||||
def init_setting(self) -> Tuple[str, Union[str, bool]]:
|
||||
"""
|
||||
模块开关设置,返回开关名和开关值,开关值为True时代表有值即打开,不实现该方法或返回None代表不使用开关
|
||||
部分模块支持同时开启多个,此时设置项以,分隔,开关值使用in判断
|
||||
"""
|
||||
pass
|
||||
|
||||
|
@ -3,7 +3,7 @@ from typing import Tuple, Union
|
||||
from app.modules import _ModuleBase
|
||||
|
||||
|
||||
class WordseModule(_ModuleBase):
|
||||
class WordsModule(_ModuleBase):
|
||||
"""
|
||||
字幕下载模块
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user