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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
import os
from Tools.Directories import *
from Screens.Menu import menuupdater
class PluginComponent:
def __init__(self):
self.plugins = []
self.setPluginPrefix("Plugins.")
self.menuEntries = []
def setPluginPrefix(self, prefix):
self.prefix = prefix
def getPluginList(self, runAutostartPlugins=False, runAutoendPlugins=False):
list = []
dir = os.listdir(resolveFilename(SCOPE_PLUGINS))
self.menuDelete()
self.menuEntries = []
for x in dir:
path = resolveFilename(SCOPE_PLUGINS, x) + "/"
# try:
if os.path.exists(path):
if fileExists(path + "plugin.py"):
pluginmodule = self.prefix + x + ".plugin"
print "trying to import " + pluginmodule
exec "import " + pluginmodule
plugin = eval(pluginmodule)
plugins = plugin.getPlugins()
try: picturepaths = plugin.getPicturePaths()
except:
picturepaths = []
for p in plugins:
picturepaths.append("")
try:
for menuEntry in plugin.getMenuRegistrationList():
self.menuEntries.append([menuEntry, pluginmodule])
except:
pass
for y in range(len(plugins)):
if len(plugins[y]) < 5:
list.append((path + picturepaths[y], plugins[y][0] , x, plugins[y][2], plugins[y][3], None, plugins[y][1]))
else:
list.append((path + picturepaths[y], plugins[y][0] , x, plugins[y][2], plugins[y][3], plugins[y][4], plugins[y][1]))
if runAutostartPlugins:
try: plugin.autostart()
except: pass
if runAutoendPlugins:
try: plugin.autoend()
except: pass
# except:
# print "Directory", path, "contains a faulty plugin"
self.menuUpdate()
return list
def menuDelete(self):
for menuEntry in self.menuEntries:
menuupdater.delMenuItem(menuEntry[0][0], menuEntry[0][1], menuEntry[0][2], menuEntry[1], menuEntry[0][3])
def menuUpdate(self):
for menuEntry in self.menuEntries:
menuupdater.addMenuItem(menuEntry[0][0], menuEntry[0][1], menuEntry[0][2], menuEntry[1], menuEntry[0][3])
def runPlugin(self, plugin, session):
try:
exec("import " + self.prefix + plugin[2] + ".plugin")
if plugin[3] == "screen":
session.open(eval(self.prefix + plugin[2] + ".plugin." + plugin[4]), plugin[5])
elif plugin[3] == "function":
eval(self.prefix + plugin[2] + ".plugin." + plugin[4])(session, plugin[5])
except:
print "exec of plugin failed!"
plugins = PluginComponent()
|