summaryrefslogtreecommitdiff
path: root/scripts/plugin.py
blob: b6f21ffe50b8a8298dc43f71639f3a5e8fdca3a1 (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
25
26
import sys

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()