-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.py
58 lines (44 loc) · 1.8 KB
/
plugins.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
###################################################################
# This file dynamically imports all plugins in the "plugins" #
# folder based on the config file in each plugin folder. #
###################################################################
import os
import importlib
lod = os.listdir("./plugins")
name = ''
enabled = ''
activate = ''
startup = ''
deactivate = ''
class setup:
startList = []
activeList = []
deactList = []
for i in lod:
with open('./plugins/%s/config' % (i)) as f: #open the plugin config
lines = f.read().splitlines()
for line in lines:
exec(line) #set each value in plugin config as variable
if enabled == True:
# import plugin named by config file, but dynamically imports any folder in "plugins" directory
spec = importlib.util.spec_from_file_location('main', "plugins/%s/main.py" %i)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
globals() [name] = mod
# add to startup and/or activate list if enabled in config file
if startup == True:
startList.append(name)
if activate == True:
activeList.append(name)
if deactivate == True:
deactList.append(name)
def dismiss(placeholder):
for i in setup.deactList:
return eval(i).deactivate()
def start(self):
# start all modules in startlist
for i in setup.startList:
eval(i).startup(self)
def active(dbrow):
for i in setup.activeList:
eval(i).activate(dbrow)