From 1dc0670c01211a1d1e8b99facea1710949ee506d Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sat, 8 Oct 2011 16:21:04 +0200 Subject: Add plugin api to template.py, add news plugin --- scripts/plugin.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 scripts/plugin.py (limited to 'scripts/plugin.py') diff --git a/scripts/plugin.py b/scripts/plugin.py new file mode 100644 index 0000000..785a219 --- /dev/null +++ b/scripts/plugin.py @@ -0,0 +1,24 @@ +class PluginManager(object): + def __init__(self): + self.plugins = [] + def register(self, plugin): + self.plugins.append(plugin) + def __getattr__(self, name): + def caller(data, *args, **kwargs): + return_value = data + processed = False + for plugin in self.plugins: + try: + method = getattr(plugin, name) + return_value = method(data, *args, **kwargs) + processed = True + except KeyError: + pass + except Exception: + sys.excepthook(*sys.exc_info()) + if not processed: + print "Warning: no plugin implemented '%s'" % name + return return_value + return caller + +plugin_manager = PluginManager() -- cgit v1.2.1