From f4217ecd3d0dac292b36ab3bedbe285345690992 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 18 Aug 2013 00:22:36 +0200 Subject: [PATCH] Move registerPlugin to __new__ magic --- couchpotato/core/loader.py | 7 +------ couchpotato/core/plugins/base.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/loader.py b/couchpotato/core/loader.py index 8aef89a4..9d04632b 100644 --- a/couchpotato/core/loader.py +++ b/couchpotato/core/loader.py @@ -111,12 +111,7 @@ class Loader(object): def loadPlugins(self, module, name): try: - klass = module.start() - klass.registerPlugin() - - if klass and getattr(klass, 'auto_register_static'): - klass.registerStatic(module.__file__) - + module.start() return True except Exception, e: log.error('Failed loading plugin "%s": %s', (module.__file__, traceback.format_exc())) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index f81d8a1b..9e97c804 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -12,6 +12,7 @@ from urlparse import urlparse import cookielib import glob import gzip +import inspect import math import os.path import re @@ -35,11 +36,20 @@ class Plugin(object): http_failed_request = {} http_failed_disabled = {} + def __new__(typ, *args, **kwargs): + new_plugin = super(Plugin, typ).__new__(typ, *args, **kwargs) + new_plugin.registerPlugin() + + return new_plugin + def registerPlugin(self): addEvent('app.do_shutdown', self.doShutdown) addEvent('plugin.running', self.isRunning) self._running = [] + if self.auto_register_static: + self.registerStatic(inspect.getfile(self.__class__)) + def conf(self, attr, value = None, default = None, section = None): return Env.setting(attr, section = section if section else self.getName().lower(), value = value, default = default)