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 ruamel.yaml import CommentedMap
from app.core.context import Context 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.context import MediaInfo, TorrentInfo
from app.core.meta import MetaBase from app.core.meta import MetaBase
from app.log import logger 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.search import SearchChain
from app.chain.subscribe import SubscribeChain from app.chain.subscribe import SubscribeChain
from app.core.config import settings 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.core.context import MediaInfo
from app.helper.rss import RssHelper from app.helper.rss import RssHelper
from app.log import logger from app.log import logger

View File

@ -1,7 +1,7 @@
from typing import Optional from typing import Optional
from app.chain import ChainBase 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.core.context import Context, MediaInfo
from app.log import logger 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.config import settings
from app.core.context import Context, MediaInfo, TorrentInfo from app.core.context import Context, MediaInfo, TorrentInfo
from app.core.meta import MetaBase 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.helper.sites import SitesHelper
from app.log import logger 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 import ChainBase
from app.chain.download import DownloadChain from app.chain.download import DownloadChain
from app.chain.search import SearchChain 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.context import TorrentInfo, Context, MediaInfo
from app.core.config import settings from app.core.config import settings
from app.db.subscribes import Subscribes from app.db.subscribes import Subscribes

View File

@ -1,7 +1,7 @@
from typing import List, Optional from typing import List, Optional
from app.chain import ChainBase 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.context import MediaInfo
from app.core.config import settings from app.core.config import settings
from app.core.meta import MetaBase 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.search import SearchChain
from app.chain.subscribe import SubscribeChain from app.chain.subscribe import SubscribeChain
from app.core.context import MediaInfo, TorrentInfo from app.core.context import MediaInfo, TorrentInfo
from app.core.meta_info import MetaInfo from app.core.metainfo import MetaInfo
from app.core.event_manager import EventManager from app.core.event import EventManager
from app.log import logger from app.log import logger
from app.utils.types import EventType 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.douban_sync import DoubanSyncChain
from app.chain.subscribe import SubscribeChain from app.chain.subscribe import SubscribeChain
from app.chain.transfer import TransferChain from app.chain.transfer import TransferChain
from app.core.event_manager import eventmanager, EventManager from app.core.event import eventmanager, EventManager
from app.core.plugin_manager import PluginManager from app.core.plugin import PluginManager
from app.core.event_manager import Event as ManagerEvent from app.core.event import Event as ManagerEvent
from app.log import logger from app.log import logger
from app.utils.singleton import Singleton from app.utils.singleton import Singleton
from app.utils.types import EventType 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.config import settings
from app.core.meta import MetaBase 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 from app.utils.types import MediaType

View File

@ -35,8 +35,11 @@ class ModuleManager(metaclass=Singleton):
module_id = module.__name__ module_id = module.__name__
self._modules[module_id] = module self._modules[module_id] = module
# 生成实例 # 生成实例
self._running_modules[module_id] = module() _module = module()
self._running_modules[module_id].init_module() # 初始化模块
if self.check_setting(_module.init_setting()):
_module.init_module()
self._running_modules[module_id] = _module
logger.info(f"Moudle Loaded{module_id}") logger.info(f"Moudle Loaded{module_id}")
def stop(self): def stop(self):
@ -47,17 +50,7 @@ class ModuleManager(metaclass=Singleton):
if hasattr(module, "stop"): if hasattr(module, "stop"):
module.stop() module.stop()
def get_modules(self, method: str) -> Generator: @staticmethod
"""
获取模块列表
"""
def check_method(func: FunctionType) -> bool:
"""
检查函数是否已实现
"""
return func.__code__.co_code != b'd\x01S\x00'
def check_setting(setting: Optional[tuple]) -> bool: def check_setting(setting: Optional[tuple]) -> bool:
""" """
检查开关是否己打开 检查开关是否己打开
@ -71,10 +64,20 @@ class ModuleManager(metaclass=Singleton):
return True return True
return False return False
def get_modules(self, method: str) -> Generator:
"""
获取模块列表
"""
def check_method(func: FunctionType) -> bool:
"""
检查函数是否已实现
"""
return func.__code__.co_code != b'd\x01S\x00'
if not self._running_modules: if not self._running_modules:
return [] return []
for _, module in self._running_modules.items(): for _, module in self._running_modules.items():
if hasattr(module, method) \ if hasattr(module, method) \
and check_method(getattr(module, method)) \ and check_method(getattr(module, method)):
and check_setting(module.init_setting()):
yield module yield module

View File

@ -8,7 +8,7 @@ from torrentool.api import Torrent
from app.core.config import settings from app.core.config import settings
from app.core.context import Context 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.log import logger
from app.utils.http import RequestUtils from app.utils.http import RequestUtils
from app.utils.string import StringUtils 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.api.apiv1 import api_router
from app.command import Command from app.command import Command
from app.core.config import settings from app.core.config import settings
from app.core.module_manager import ModuleManager from app.core.module import ModuleManager
from app.core.plugin_manager import PluginManager from app.core.plugin import PluginManager
from app.db.init import init_db, update_db from app.db.init import init_db, update_db
from app.helper.sites import SitesHelper from app.helper.sites import SitesHelper
from app.scheduler import Scheduler 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.context import MediaInfo
from app.core.config import settings 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.core.meta import MetaBase
from app.log import logger from app.log import logger
from app.modules import _ModuleBase from app.modules import _ModuleBase
@ -18,12 +18,10 @@ from app.utils.types import MediaType
class Douban(_ModuleBase): class Douban(_ModuleBase):
def __init__(self): doubanapi: DoubanApi = None
super().__init__()
self.doubanapi = DoubanApi()
def init_module(self) -> None: def init_module(self) -> None:
pass self.doubanapi = DoubanApi()
def stop(self): def stop(self):
pass pass

View File

@ -6,7 +6,7 @@ from typing import Optional, List, Tuple, Union
from jinja2 import Template from jinja2 import Template
from app.core.context import MediaInfo 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.config import settings
from app.core.meta import MetaBase from app.core.meta import MetaBase
from app.log import logger from app.log import logger

View File

@ -2,7 +2,7 @@ from pathlib import Path
from typing import Set, Tuple, Optional, Union, List from typing import Set, Tuple, Optional, Union, List
from app.core.config import settings 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 import _ModuleBase
from app.modules.qbittorrent.qbittorrent import Qbittorrent from app.modules.qbittorrent.qbittorrent import Qbittorrent
from app.utils.string import StringUtils from app.utils.string import StringUtils

View File

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

View File

@ -5,7 +5,7 @@ from xml.dom import minidom
from app.core.config import settings from app.core.config import settings
from app.core.context import MediaInfo 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.core.meta import MetaBase
from app.log import logger from app.log import logger
from app.modules import _ModuleBase from app.modules import _ModuleBase

View File

@ -2,7 +2,7 @@ from pathlib import Path
from typing import Set, Tuple, Optional, Union, List from typing import Set, Tuple, Optional, Union, List
from app.core.config import settings 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 import _ModuleBase
from app.modules.transmission.transmission import Transmission from app.modules.transmission.transmission import Transmission
from app.utils.types import TorrentStatus from app.utils.types import TorrentStatus

View File

@ -7,7 +7,7 @@ from urllib.parse import urljoin
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from ruamel.yaml import CommentedMap 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.core.config import settings
from app.helper.browser import PlaywrightHelper from app.helper.browser import PlaywrightHelper
from app.helper.cloudflare import under_challenge 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 ruamel.yaml import CommentedMap
from app.core.config import settings from app.core.config import settings
from app.core.event_manager import eventmanager from app.core.event import eventmanager
from app.core.event_manager import Event from app.core.event import Event
from app.helper.browser import PlaywrightHelper from app.helper.browser import PlaywrightHelper
from app.helper.module import ModuleHelper from app.helper.module import ModuleHelper
from app.helper.sites import SitesHelper from app.helper.sites import SitesHelper

View File

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