Skip to content

Commit 76e2c16

Browse files
committed
feat(extensions): start building an interface to split notifiers, providers, metadata, clients, etc out into namespaced plugin packages
Signed-off-by: miigotu <[email protected]>
1 parent 5901e86 commit 76e2c16

File tree

3 files changed

+51
-153
lines changed

3 files changed

+51
-153
lines changed

sickchill/extensions/manager.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import importlib
2+
import pkgutil
3+
4+
from sickchill import logger, settings
5+
from sickchill.oldbeard import config
6+
7+
import sickchill.extensions
8+
9+
10+
def iter_namespace(ns_pkg):
11+
return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".")
12+
13+
14+
def discover():
15+
global extenstions
16+
extensions = {}
17+
for finder, name, ispkg in iter_namespace(sickchill.extensions):
18+
if name == __name__:
19+
continue
20+
try:
21+
plugin = importlib.import_module(name)
22+
extensions[name] = plugin
23+
except Exception as e:
24+
logger.debug("Error importing extension: {0}".format(name), exc_info=e)
25+
26+
config.check_section(settings.CFG, "extensions")
27+
for extension in extensions:
28+
logger.debug("Loading {extension} from {path}".format(extension=extension, path=extensions[extension].__path__))
29+
config.check_section(settings.CFG["extensions"], extension.name)
30+
31+
global clients, providers, metadata, notifiers, indexers, post_processors
32+
33+
# Clients
34+
clients = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Client")}
35+
36+
# Providers
37+
providers = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Provider")}
38+
39+
# Metadata
40+
metadata = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Metadata")}
41+
42+
# Notifiers
43+
notifiers = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Notifier")}
44+
45+
# TVDB, TVMAZE, TMDB, etc
46+
indexers = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "Indexer")}
47+
48+
# Post Processors
49+
post_processors = {extension.name: extension for name, extension in extensions.items() if hasattr(extension, "PostProcessor")}

sickchill/oldbeard/stevedore.py

Lines changed: 0 additions & 152 deletions
This file was deleted.

sickchill/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
if TYPE_CHECKING:
1313
from .movies import MovieList
14+
from configobj import ConfigObj
1415

1516
setup_gettext()
1617

@@ -84,7 +85,7 @@
8485
CALENDAR_UNPROTECTED = False
8586
CF_AUTH_DOMAIN = ""
8687
CF_POLICY_AUD = ""
87-
CFG = None
88+
CFG: "ConfigObj" = None
8889
CHECK_PROPERS_INTERVAL = None
8990
CLIENT_WEB_URLS = {"torrent": "", "newznab": ""}
9091
COMING_EPS_DISPLAY_PAUSED = False

0 commit comments

Comments
 (0)