-
Notifications
You must be signed in to change notification settings - Fork 1
/
pluginloader.py
executable file
·56 lines (43 loc) · 1.49 KB
/
pluginloader.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
# Bring in the error handlers
import handlers
# Setting up globals
loadedPlugins = {}
# Initialize a plugin and import it
def init(name):
try:
loadedPlugins[name] = __import__('plugins.' + name + '.main', fromlist=[
'main']) # fromlist stops it from importing as the root module? python is weird
loadedPlugins[name].init()
except Exception as e:
handlers.err("loading plugin " + name + " :: Exception raised :: " + str(e))
# Get rid of a plugin
def unload(name):
del (loadedPlugins[name])
# Runs an individual plugin print function
def printPlugin(name, printer):
try:
printer.text("\n")
loadedPlugins[name].run(printer)
printer.text("\n")
except Exception as e:
handlers.err("running print for plugin " + name + " :: Exception raised :: " + str(e))
# Runs all plugins' print functions
def printAllPlugins(printer):
for plugin in loadedPlugins:
printPlugin(plugin, printer)
# Runs an individual plugin e-ink update function
def updatePlugin(name):
pinfo = __import__('plugins.' + name, fromlist=[str(name)])
try:
pinfo.haseink
except AttributeError:
return False
else:
try:
loadedPlugins[name].update()
except Exception as e:
handlers.err("running print for plugin " + name + " :: Exception raised :: " + str(e))
# Runs all plugins' update functions
def updateAllPlugins():
for plugin in loadedPlugins:
updatePlugin(plugin)