summaryrefslogtreecommitdiff
path: root/src/plugin_manager.py
blob: 3f900e39b1b959ffe2a38d8c0fe1f7282fa2b2d7 (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
class PluginManager(object):
    def __init__(self, core):
        self.core = core
        self.plugins = {}

    def load(self, name):
        if name in self.plugins:
            self.plugins[name].unload()

        try:
            code = compile(open(name).read(), name, 'exec')
            from plugin import BasePlugin
            globals = { 'BasePlugin' : BasePlugin }
            exec(code, globals)
            self.plugins[name] = globals['Plugin'](self.core)
        except Exception as e:
            self.core.information("Could not load plugin: %s" % (e,))

    def unload(self, name):
        if name in self.plugins:
            try:
                self.plugins[name].unload()
                del self.plugins[name]
            except Exception as e:
                self.core.information("Could not unload plugin (may not be safe to try again): %s" % (e,))