]> jfr.im git - irc/evilnet/x3.git/blob - src/plugins/__init__.py
fix a couple oversights in building ldap add structs
[irc/evilnet/x3.git] / src / plugins / __init__.py
1 import imp
2 import os.path
3
4 class Plugin(object):
5 def server_link(self, server):
6 pass
7
8 def new_user(self, user):
9 pass
10
11 def nick_change(self, user, oldnick):
12 pass
13
14 def del_user(self, user, killer, why):
15 pass
16
17 def topic(self, who, chan, old_topic):
18 pass
19
20 def load_path(path, prefix):
21 mods = []
22
23 for entry in os.listdir(path):
24 if os.path.isfile(os.path.join(path, entry)):
25 if os.path.splitext(entry)[1] != '.py':
26 continue
27
28 if entry.startswith('.') or entry.startswith('__'):
29 continue
30
31 try:
32 args = imp.find_module(os.path.splitext(entry)[0], [path])
33 except ImportError:
34 continue
35
36 if args:
37 mod = imp.load_module(prefix + os.path.splitext(entry)[0], *args)
38 if args[0]:
39 args[0].close()
40 if mod:
41 mods.append(mod)
42
43 if os.path.isdir(os.path.join(path, entry)):
44 mods.extend(load_path(os.path.join(path, entry), prefix + entry + '.'))
45
46 return mods
47
48 def load():
49 mods = load_path(os.path.dirname(__file__), 'plugins.')
50 plugins = {}
51
52 # for some reason this returns multiple instances of the same plugin types
53 candidates = Plugin.__subclasses__()
54 for plg in candidates:
55 if plg.__name__ not in plugins:
56 plugins[plg.__name__] = plg()
57
58 return plugins.values()