Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
36 lines (31 loc) · 1.08 KB

File metadata and controls

36 lines (31 loc) · 1.08 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import imp
import os
MAIN_MODULE = "__init__"
class PluginNotFoundError(NameError):
pass
def get_plugins(plugin_folder):
plugins = []
possible_plugins = os.listdir(plugin_folder)
for i in possible_plugins:
location = os.path.join(plugin_folder, i)
if os.path.isdir(location) and (MAIN_MODULE + ".py") in os.listdir(location):
name = i
info = imp.find_module(MAIN_MODULE, [location])
elif not os.path.isdir(location) and location.endswith(".py"):
name = i.rpartition(".py")[0]
info = imp.find_module(name, [plugin_folder])
else:
continue
plugins.append({"name": name, "info": info})
return plugins
def get_plugin_by_name(plugin_name, plugin_folder):
for plugin in get_plugins(plugin_folder):
if plugin['name'] == plugin_name:
return load_plugin(plugin)
raise PluginNotFoundError()
def load_plugin(plugin):
try:
return imp.load_module(plugin["name"], *plugin["info"])
finally:
fp = plugin["info"][0]
if fp: fp.close()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.