summaryrefslogtreecommitdiff
path: root/scripts/plugin.py
blob: 08f046143b84668cb12146c3969441df6a11d410 (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(return_value, *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()