1 Star 0 Fork 58

James.w / bitinsight

forked from compilelife / bitinsight 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
plugin.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
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
Python
1
https://gitee.com/xiangshan/bitinsight.git
git@gitee.com:xiangshan/bitinsight.git
xiangshan
bitinsight
bitinsight
master

搜索帮助