|
| 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")} |
0 commit comments