]>
Commit | Line | Data |
---|---|---|
685e346e A |
1 | import traceback |
2 | import logging | |
3 | import task | |
4 | ||
5 | from core import * | |
6 | ||
7 | class AcidPlugin(object): | |
8 | def __init__(self): | |
9 | super(AcidPlugin, self).__init__() | |
10 | ||
11 | self.prefix = config.get('control', 'prefix') | |
12 | self.logchan = config.get('control', 'channel') | |
13 | self.log = logging.getLogger(__name__) | |
14 | self.config = config | |
15 | self.dbp = dbx.cursor() | |
16 | ||
17 | def start(self): | |
18 | pass | |
19 | ||
20 | def stop(self): | |
21 | pass | |
22 | ||
23 | def getCommands(self): | |
24 | pass | |
25 | ||
26 | modules = {} | |
27 | plugin_to_modname = lambda x: '%s.%s' % (x, x) | |
28 | ||
29 | def loadPlugin(plugin, inter): | |
30 | import importlib | |
31 | ||
32 | global modules | |
33 | ||
34 | modname = plugin_to_modname(plugin) | |
35 | ||
36 | mod = importlib.import_module(modname) | |
37 | obj = getattr(mod, plugin)() | |
38 | ||
39 | obj.inter = inter | |
40 | ||
41 | obj.start() | |
42 | ||
43 | modules[modname] = obj | |
44 | ||
45 | def unloadPlugin(plugin): | |
46 | global modules | |
47 | ||
48 | modname = plugin_to_modname(plugin) | |
49 | ||
50 | obj = modules[modname] | |
51 | obj.stop() | |
52 | ||
53 | deps = [module for module in sys.modules if module.startswith(modname + '.')] | |
54 | for dep in deps: | |
55 | del sys.modules[dep] | |
56 | if plugin in sys.modules: | |
57 | del sys.modules[modname] | |
58 | ||
59 | del sys.modules[modname] | |
60 | del modules[modname] | |
61 | ||
62 | def getPlugins(): | |
63 | return modules.keys() | |
64 | ||
65 | def call(name, *args): | |
66 | task.Run() | |
67 | ||
68 | for m in modules.itervalues(): | |
69 | try: | |
70 | func = getattr(m, name) | |
71 | except: | |
72 | continue | |
73 | ||
74 | try: | |
75 | func(*args) | |
76 | except: | |
77 | traceback.print_exc() | |
78 | raise |