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