-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpluginloader.py
More file actions
31 lines (25 loc) · 873 Bytes
/
pluginloader.py
File metadata and controls
31 lines (25 loc) · 873 Bytes
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
#!/opt/csw/bin/python
# coding=utf-8
import imp
import os
CommandPluginFolder = "./plugin/command"
InterceptorPluginFolder = "./plugin/interceptor"
MainModule = "__init__"
def findAllCommandPlugins():
return findAllPlugins(CommandPluginFolder)
def findAllInterceptorPlugins():
return findAllPlugins(InterceptorPluginFolder)
def findAllPlugins(folder):
plugins = {}
for i in os.listdir(folder):
location = os.path.join(folder, i)
if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location):
continue
info = imp.find_module(MainModule, [location])
plugin = {"name": i, "info": info}
commands = load(plugin).getCommands()
plugin["commands"] = commands
plugins[i] = plugin
return plugins
def load(plugin):
return imp.load_module(MainModule, *plugin["info"])