Move registerPlugin to __new__ magic

This commit is contained in:
Ruud committed 2013-08-18 00:22:36 +02:00
1 parent 4348451692
commit f4217ecd3d
2 files changed
+11 -6

No files matched your search

+1 -6
View File
@@ -111,12 +111,7 @@ class Loader(object):
def loadPlugins(self, module, name): def loadPlugins(self, module, name):
try: try:
klass = module.start() module.start()
klass.registerPlugin()
if klass and getattr(klass, 'auto_register_static'):
klass.registerStatic(module.__file__)
return True return True
except Exception, e: except Exception, e:
log.error('Failed loading plugin "%s": %s', (module.__file__, traceback.format_exc())) log.error('Failed loading plugin "%s": %s', (module.__file__, traceback.format_exc()))
+10
View File
@@ -12,6 +12,7 @@ from urlparse import urlparse
import cookielib import cookielib
import glob import glob
import gzip import gzip
import inspect
import math import math
import os.path import os.path
import re import re
@@ -35,11 +36,20 @@ class Plugin(object):
http_failed_request = {} http_failed_request = {}
http_failed_disabled = {} 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): def registerPlugin(self):
addEvent('app.do_shutdown', self.doShutdown) addEvent('app.do_shutdown', self.doShutdown)
addEvent('plugin.running', self.isRunning) addEvent('plugin.running', self.isRunning)
self._running = [] self._running = []
if self.auto_register_static:
self.registerStatic(inspect.getfile(self.__class__))
def conf(self, attr, value = None, default = None, section = None): 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) return Env.setting(attr, section = section if section else self.getName().lower(), value = value, default = default)