fix modules

This commit is contained in:
jxxghp 2023-06-10 09:51:20 +08:00
parent e86bb84ba5
commit e0730960d3
24 changed files with 47 additions and 49 deletions

View File

@ -6,7 +6,7 @@ from typing import Optional, Any, Tuple, List, Set, Union
from ruamel.yaml import CommentedMap
from app.core.context import Context
from app.core.module_manager import ModuleManager
from app.core.module import ModuleManager
from app.core.context import MediaInfo, TorrentInfo
from app.core.meta import MetaBase
from app.log import logger

View File

@ -6,7 +6,7 @@ from app.chain.download import DownloadChain
from app.chain.search import SearchChain
from app.chain.subscribe import SubscribeChain
from app.core.config import settings
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.context import MediaInfo
from app.helper.rss import RssHelper
from app.log import logger

View File

@ -1,7 +1,7 @@
from typing import Optional
from app.chain import ChainBase
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.context import Context, MediaInfo
from app.log import logger

View File

@ -4,7 +4,7 @@ from app.chain import ChainBase
from app.core.config import settings
from app.core.context import Context, MediaInfo, TorrentInfo
from app.core.meta import MetaBase
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.helper.sites import SitesHelper
from app.log import logger

View File

@ -3,7 +3,7 @@ from typing import Dict, List, Optional
from app.chain import ChainBase
from app.chain.download import DownloadChain
from app.chain.search import SearchChain
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.context import TorrentInfo, Context, MediaInfo
from app.core.config import settings
from app.db.subscribes import Subscribes

View File

@ -1,7 +1,7 @@
from typing import List, Optional
from app.chain import ChainBase
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.context import MediaInfo
from app.core.config import settings
from app.core.meta import MetaBase

View File

@ -4,8 +4,8 @@ from app.chain.download import *
from app.chain.search import SearchChain
from app.chain.subscribe import SubscribeChain
from app.core.context import MediaInfo, TorrentInfo
from app.core.meta_info import MetaInfo
from app.core.event_manager import EventManager
from app.core.metainfo import MetaInfo
from app.core.event import EventManager
from app.log import logger
from app.utils.types import EventType

View File

@ -7,9 +7,9 @@ from app.chain.cookiecloud import CookieCloudChain
from app.chain.douban_sync import DoubanSyncChain
from app.chain.subscribe import SubscribeChain
from app.chain.transfer import TransferChain
from app.core.event_manager import eventmanager, EventManager
from app.core.plugin_manager import PluginManager
from app.core.event_manager import Event as ManagerEvent
from app.core.event import eventmanager, EventManager
from app.core.plugin import PluginManager
from app.core.event import Event as ManagerEvent
from app.log import logger
from app.utils.singleton import Singleton
from app.utils.types import EventType

View File

@ -2,7 +2,7 @@ from typing import Optional, Any, List
from app.core.config import settings
from app.core.meta import MetaBase
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.utils.types import MediaType

View File

@ -35,9 +35,12 @@ class ModuleManager(metaclass=Singleton):
module_id = module.__name__
self._modules[module_id] = module
# 生成实例
self._running_modules[module_id] = module()
self._running_modules[module_id].init_module()
logger.info(f"Moudle Loaded{module_id}")
_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}")
def stop(self):
"""
@ -47,6 +50,20 @@ class ModuleManager(metaclass=Singleton):
if hasattr(module, "stop"):
module.stop()
@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:
return True
return False
def get_modules(self, method: str) -> Generator:
"""
获取模块列表
@ -58,23 +75,9 @@ class ModuleManager(metaclass=Singleton):
"""
return func.__code__.co_code != b'd\x01S\x00'
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:
return True
return False
if not self._running_modules:
return []
for _, module in self._running_modules.items():
if hasattr(module, method) \
and check_method(getattr(module, method)) \
and check_setting(module.init_setting()):
and check_method(getattr(module, method)):
yield module

View File

@ -8,7 +8,7 @@ from torrentool.api import Torrent
from app.core.config import settings
from app.core.context import Context
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.log import logger
from app.utils.http import RequestUtils
from app.utils.string import StringUtils

View File

@ -5,8 +5,8 @@ from uvicorn import Config
from app.api.apiv1 import api_router
from app.command import Command
from app.core.config import settings
from app.core.module_manager import ModuleManager
from app.core.plugin_manager import PluginManager
from app.core.module import ModuleManager
from app.core.plugin import PluginManager
from app.db.init import init_db, update_db
from app.helper.sites import SitesHelper
from app.scheduler import Scheduler

View File

@ -5,7 +5,7 @@ from xml.dom import minidom
from app.core.context import MediaInfo
from app.core.config import settings
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.meta import MetaBase
from app.log import logger
from app.modules import _ModuleBase
@ -18,12 +18,10 @@ from app.utils.types import MediaType
class Douban(_ModuleBase):
def __init__(self):
super().__init__()
self.doubanapi = DoubanApi()
doubanapi: DoubanApi = None
def init_module(self) -> None:
pass
self.doubanapi = DoubanApi()
def stop(self):
pass

View File

@ -6,7 +6,7 @@ from typing import Optional, List, Tuple, Union
from jinja2 import Template
from app.core.context import MediaInfo
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.config import settings
from app.core.meta import MetaBase
from app.log import logger

View File

@ -2,7 +2,7 @@ from pathlib import Path
from typing import Set, Tuple, Optional, Union, List
from app.core.config import settings
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.modules import _ModuleBase
from app.modules.qbittorrent.qbittorrent import Qbittorrent
from app.utils.string import StringUtils

View File

@ -20,9 +20,6 @@ class Telegram(metaclass=Singleton):
"""
初始化参数
"""
if settings.MESSAGER != "telegram":
return
# Token
self._telegram_token = settings.TELEGRAM_TOKEN
# Chat Id

View File

@ -5,7 +5,7 @@ from xml.dom import minidom
from app.core.config import settings
from app.core.context import MediaInfo
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.core.meta import MetaBase
from app.log import logger
from app.modules import _ModuleBase

View File

@ -2,7 +2,7 @@ from pathlib import Path
from typing import Set, Tuple, Optional, Union, List
from app.core.config import settings
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from app.modules import _ModuleBase
from app.modules.transmission.transmission import Transmission
from app.utils.types import TorrentStatus

View File

@ -7,7 +7,7 @@ from urllib.parse import urljoin
from apscheduler.schedulers.background import BackgroundScheduler
from ruamel.yaml import CommentedMap
from app.core.event_manager import EventManager, eventmanager
from app.core.event import EventManager, eventmanager
from app.core.config import settings
from app.helper.browser import PlaywrightHelper
from app.helper.cloudflare import under_challenge

View File

@ -8,8 +8,8 @@ from apscheduler.schedulers.background import BackgroundScheduler
from ruamel.yaml import CommentedMap
from app.core.config import settings
from app.core.event_manager import eventmanager
from app.core.event_manager import Event
from app.core.event import eventmanager
from app.core.event import Event
from app.helper.browser import PlaywrightHelper
from app.helper.module import ModuleHelper
from app.helper.sites import SitesHelper

View File

@ -2,7 +2,7 @@
from unittest import TestCase
from app.core.meta_info import MetaInfo
from app.core.metainfo import MetaInfo
from tests.cases.meta import meta_cases