diff --git a/couchpotato/core/loader.py b/couchpotato/core/loader.py index 2812364b..11ce931c 100644 --- a/couchpotato/core/loader.py +++ b/couchpotato/core/loader.py @@ -80,10 +80,14 @@ class Loader: def loadPlugins(self, module, name): try: - module.start() + klass = module.start() + + if klass and getattr(klass, 'auto_register_static'): + klass.registerStatic(module.__file__) + return True except Exception, e: - log.error("Failed loading plugin '%s': %s" % (name, traceback.format_exc())) + log.error("Failed loading plugin '%s': %s" % (module.__file__, traceback.format_exc())) return False def addModule(self, priority, type, module, name): diff --git a/couchpotato/core/notifications/core/main.py b/couchpotato/core/notifications/core/main.py index 1756d2fd..0b3d1e06 100644 --- a/couchpotato/core/notifications/core/main.py +++ b/couchpotato/core/notifications/core/main.py @@ -15,11 +15,19 @@ class CoreNotifier(Notification): def __init__(self): addEvent('notify', self.notify) - addEvent('notify.core', self.frontend) + addEvent('notify.frontend', self.frontend) addApiView('core_notifier.listener', self.listener) - self.registerStatic(__file__) + self.registerEvents() + + + def registerEvents(self): + + # Library update, frontend refresh + def onLibraryUpdate(data): + fireEvent('notify.frontend', type = 'library.update', data = data) + addEvent('library.update', onLibraryUpdate) def notify(self, message = '', data = {}, type = None): self.add(data = { @@ -38,7 +46,6 @@ class CoreNotifier(Notification): messages = [] for message in self.messages: - print message['time'], (time.time() - 5) #delete message older then 15s if message['time'] > (time.time() - 15): messages.append(message) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index e704159b..6ba27446 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -14,6 +14,7 @@ log = CPLog(__name__) class Plugin(object): enabled_option = 'enabled' + auto_register_static = True def conf(self, attr, default = None): return Env.setting(attr, self.getName().lower(), default = default) diff --git a/couchpotato/core/plugins/browser/main.py b/couchpotato/core/plugins/browser/main.py index c364c3c2..d4829b40 100644 --- a/couchpotato/core/plugins/browser/main.py +++ b/couchpotato/core/plugins/browser/main.py @@ -1,12 +1,13 @@ from couchpotato.api import addApiView from couchpotato.core.helpers.request import getParam, jsonified +from couchpotato.core.plugins.base import Plugin import os import string if os.name == 'nt': import win32file -class FileBrowser(): +class FileBrowser(Plugin): def __init__(self): addApiView('directory.list', self.view) diff --git a/couchpotato/core/plugins/extension/main.py b/couchpotato/core/plugins/extension/main.py index 80d18e5d..9992779f 100644 --- a/couchpotato/core/plugins/extension/main.py +++ b/couchpotato/core/plugins/extension/main.py @@ -3,5 +3,7 @@ from couchpotato.core.plugins.base import Plugin class Extension(Plugin): + auto_register_static = False + def __init__(self): self.registerStatic(__file__, add_to_head = False) diff --git a/couchpotato/core/plugins/file/main.py b/couchpotato/core/plugins/file/main.py index 53f98ba2..5a9c8a23 100644 --- a/couchpotato/core/plugins/file/main.py +++ b/couchpotato/core/plugins/file/main.py @@ -25,8 +25,6 @@ class FileManager(Plugin): addApiView('file.cache/', self.showImage) - self.registerStatic(__file__) - def showImage(self, file = ''): cache_dir = Env.get('cache_dir') diff --git a/couchpotato/core/plugins/library/main.py b/couchpotato/core/plugins/library/main.py index 309cf723..71d2a511 100644 --- a/couchpotato/core/plugins/library/main.py +++ b/couchpotato/core/plugins/library/main.py @@ -100,6 +100,6 @@ class LibraryPlugin(Plugin): library_dict = library.to_dict({'titles': {}, 'files':{}}) - fireEvent('notify.core', type = 'library.update', data = library_dict) + fireEvent('library.update', data = library_dict) return library_dict diff --git a/couchpotato/core/plugins/metadata/main.py b/couchpotato/core/plugins/metadata/main.py index 4bb3ab0f..1a6e6e57 100644 --- a/couchpotato/core/plugins/metadata/main.py +++ b/couchpotato/core/plugins/metadata/main.py @@ -10,8 +10,6 @@ class MetaData(Plugin): def __init__(self): addEvent('renaming.after', self.add) - self.registerStatic(__file__) - addEvent('app.load', self.add) def add(self, data = {}): diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index 4763d444..a48abccb 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -19,8 +19,6 @@ class MoviePlugin(Plugin): addApiView('movie.edit', self.edit) addApiView('movie.delete', self.delete) - self.registerStatic(__file__) - def list(self): params = getParams() diff --git a/couchpotato/core/plugins/profile/main.py b/couchpotato/core/plugins/profile/main.py index 72512036..b43a6e6a 100644 --- a/couchpotato/core/plugins/profile/main.py +++ b/couchpotato/core/plugins/profile/main.py @@ -17,8 +17,6 @@ class ProfilePlugin(Plugin): addApiView('profile.save', self.save) addApiView('profile.delete', self.delete) - self.registerStatic(__file__) - def all(self): db = get_session() diff --git a/couchpotato/core/plugins/quality/main.py b/couchpotato/core/plugins/quality/main.py index 1d8a489d..406697ca 100644 --- a/couchpotato/core/plugins/quality/main.py +++ b/couchpotato/core/plugins/quality/main.py @@ -33,8 +33,6 @@ class QualityPlugin(Plugin): addEvent('quality.guess', self.guess) addEvent('app.load', self.fill) - self.registerStatic(__file__) - def all(self): db = get_session() diff --git a/couchpotato/core/plugins/status/main.py b/couchpotato/core/plugins/status/main.py index 73a634a5..89e62d63 100644 --- a/couchpotato/core/plugins/status/main.py +++ b/couchpotato/core/plugins/status/main.py @@ -26,8 +26,6 @@ class StatusPlugin(Plugin): addEvent('status.all', self.all) addEvent('app.load', self.fill) - self.registerStatic(__file__) - def all(self): db = get_session() diff --git a/couchpotato/core/plugins/wizard/main.py b/couchpotato/core/plugins/wizard/main.py index 9d1aeca3..1c93c9f9 100644 --- a/couchpotato/core/plugins/wizard/main.py +++ b/couchpotato/core/plugins/wizard/main.py @@ -1,4 +1,3 @@ -from couchpotato.core.event import fireEvent from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin @@ -6,6 +5,4 @@ log = CPLog(__name__) class Wizard(Plugin): - - def __init__(self): - self.registerStatic(__file__) + pass diff --git a/couchpotato/core/providers/metadata/base.py b/couchpotato/core/providers/metadata/base.py index c5775832..0403f630 100644 --- a/couchpotato/core/providers/metadata/base.py +++ b/couchpotato/core/providers/metadata/base.py @@ -1,8 +1,6 @@ from couchpotato.core.event import addEvent from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin -from couchpotato.environment import Env -import os log = CPLog(__name__) diff --git a/couchpotato/core/providers/movie/imdb/__init__.py b/couchpotato/core/providers/movie/imdb/__init__.py index 3442847b..f10505da 100644 --- a/couchpotato/core/providers/movie/imdb/__init__.py +++ b/couchpotato/core/providers/movie/imdb/__init__.py @@ -1,4 +1,6 @@ +from .main import IMDB + def start(): - pass + return IMDB() config = [] diff --git a/couchpotato/core/providers/nzb/newznab/main.py b/couchpotato/core/providers/nzb/newznab/main.py index c1b1baf0..b495fe2e 100644 --- a/couchpotato/core/providers/nzb/newznab/main.py +++ b/couchpotato/core/providers/nzb/newznab/main.py @@ -31,11 +31,6 @@ class Newznab(NZBProvider, RSS): time_between_searches = 1 # Seconds - def __init__(self): - super(NZBProvider, self).__init__() - - self.registerStatic(__file__) - def feed(self): hosts = self.getHosts()