diff options
author | Christian Franke <nobody@nowhere.ws> | 2011-10-08 16:21:04 +0200 |
---|---|---|
committer | Christian Franke <nobody@nowhere.ws> | 2011-10-08 17:44:40 +0200 |
commit | 1dc0670c01211a1d1e8b99facea1710949ee506d (patch) | |
tree | f373c744fcc4a27a62070d757887589db5f7739e /scripts/plugin.py | |
parent | f43a8028cdf482d72efe82fdf101915df049fdc3 (diff) |
Add plugin api to template.py, add news plugin
Diffstat (limited to 'scripts/plugin.py')
-rw-r--r-- | scripts/plugin.py | 24 |
1 files changed, 24 insertions, 0 deletions
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() |