-
Notifications
You must be signed in to change notification settings - Fork 28
/
plugin.py
39 lines (35 loc) · 1.03 KB
/
plugin.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
from importlib import import_module
import inspect
from table import Table
from bitstream import BitStream
from doc import Doc
class Plugin:
def __init__(self):
self.exports = {}
self.doc = Doc()
self.default = ''
self.name = ''
def load_plugin(name):
mod = import_module('.main', 'plugins.'+name)
bs = BitStream(bytes([]))
t = Table('inspect', None, bs)
plugin = Plugin()
plugin.name = name
for attr in dir(mod):
if attr.startswith('__'):
continue
obj = getattr(mod, attr)
if not inspect.isfunction(obj):
continue
sig = inspect.signature(obj)
try:
sig.bind(t, bs)
if attr == 'default_parser':
plugin.default = attr
plugin.exports[attr] = obj
except TypeError as e:
continue
if len(plugin.default) == 0 and len(plugin.exports) > 0:
plugin.default = list(plugin.exports.keys())[0]
plugin.doc.parse('plugins/'+name+'/doc.md')
return plugin