summaryrefslogtreecommitdiff
path: root/scripts/plugin.py
blob: 785a2197c19696ec5e2e3c30a748a8903418c3bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()