From 6da9224735dbb92dff18581d045b9213b6eededc Mon Sep 17 00:00:00 2001 From: miigotu Date: Sat, 22 Oct 2022 19:01:18 -0400 Subject: [PATCH 1/4] feat(extensions): start building an interface to split notifiers, providers, metadata, clients, etc out into namespaced plugin packages Signed-off-by: miigotu --- sickchill/extensions/manager.py | 49 +++++++++++++++++++++++++++++++++ sickchill/settings.py | 3 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 sickchill/extensions/manager.py diff --git a/sickchill/extensions/manager.py b/sickchill/extensions/manager.py new file mode 100644 index 0000000000..984f2d1fd3 --- /dev/null +++ b/sickchill/extensions/manager.py @@ -0,0 +1,49 @@ +import importlib +import pkgutil + +from sickchill import logger, settings +from sickchill.oldbeard import config + +import sickchill.extensions + + +def iter_namespace(ns_pkg): + return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".") + + +def discover(): + global extenstions + extensions = {} + for finder, name, ispkg in iter_namespace(sickchill.extensions): + if name == __name__: + continue + try: + plugin = importlib.import_module(name) + extensions[name] = plugin + except Exception as e: + logger.debug("Error importing extension: {0}".format(name), exc_info=e) + + config.check_section(settings.CFG, "extensions") + for extension in extensions: + logger.debug("Loading {extension} from {path}".format(extension=extension, path=extensions[extension].__path__)) + config.check_section(settings.CFG["extensions"], extension.name) + + global clients, providers, metadata, notifiers, indexers, post_processors + + # Clients + clients = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Client")} + + # Providers + providers = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Provider")} + + # Metadata + metadata = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Metadata")} + + # Notifiers + notifiers = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Notifier")} + + # TVDB, TVMAZE, TMDB, etc + indexers = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Indexer")} + + # Post Processors + post_processors = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "PostProcessor")} diff --git a/sickchill/settings.py b/sickchill/settings.py index fe09a7c1f8..5bc5739882 100644 --- a/sickchill/settings.py +++ b/sickchill/settings.py @@ -11,6 +11,7 @@ if TYPE_CHECKING: from .movies import MovieList + from configobj import ConfigObj setup_gettext() @@ -84,7 +85,7 @@ CALENDAR_UNPROTECTED = False CF_AUTH_DOMAIN = "" CF_POLICY_AUD = "" -CFG = None +CFG: "ConfigObj" = None CHECK_PROPERS_INTERVAL = None CLIENT_WEB_URLS = {"torrent": "", "newznab": ""} COMING_EPS_DISPLAY_PAUSED = False From f3561ae1d2cc4774620d9a13ed55a2dafd85361c Mon Sep 17 00:00:00 2001 From: miigotu Date: Thu, 23 Mar 2023 08:06:06 -0400 Subject: [PATCH 2/4] Update manager.py --- sickchill/extensions/manager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sickchill/extensions/manager.py b/sickchill/extensions/manager.py index 984f2d1fd3..294925f6b8 100644 --- a/sickchill/extensions/manager.py +++ b/sickchill/extensions/manager.py @@ -1,11 +1,10 @@ import importlib import pkgutil +import sickchill.extensions from sickchill import logger, settings from sickchill.oldbeard import config -import sickchill.extensions - def iter_namespace(ns_pkg): return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".") From 31a1a4e8745baa661ebdbe971673d01bd8a7b2b8 Mon Sep 17 00:00:00 2001 From: miigotu Date: Thu, 23 Mar 2023 08:07:58 -0400 Subject: [PATCH 3/4] Update settings.py --- sickchill/settings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sickchill/settings.py b/sickchill/settings.py index 5bc5739882..c340942ebf 100644 --- a/sickchill/settings.py +++ b/sickchill/settings.py @@ -10,8 +10,9 @@ from .init_helpers import setup_gettext, sickchill_dir if TYPE_CHECKING: - from .movies import MovieList from configobj import ConfigObj + + from .movies import MovieList setup_gettext() From 8e7df601777bd734f94f04cccc02dfdb8f2c9c9f Mon Sep 17 00:00:00 2001 From: miigotu Date: Thu, 23 Mar 2023 08:16:02 -0400 Subject: [PATCH 4/4] Update settings.py --- sickchill/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sickchill/settings.py b/sickchill/settings.py index c340942ebf..0255bfd719 100644 --- a/sickchill/settings.py +++ b/sickchill/settings.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from configobj import ConfigObj - + from .movies import MovieList setup_gettext()