aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/PluginComponent.py
blob: 0b4070218b5462a65a3fb06e633c04d1f81f4aea (plain)
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
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):
		list = []
		dir = os.listdir(resolveFilename(SCOPE_PLUGINS))
		self.menuDelete()
		self.menuEntries = []

		for x in dir:
			path = resolveFilename(SCOPE_PLUGINS, x) + "/"
			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)
					picturepath = plugin.getPicturePath()
					pluginname = plugin.getPluginName()
					try:
						for menuEntry in plugin.getMenuRegistrationList():
							self.menuEntries.append([menuEntry, pluginmodule])
					except:
						pass
	
					list.append((picturepath, pluginname , x))
		self.menuUpdate()
		return list
	
	def menuDelete(self):
		for menuEntry in self.menuEntries:
			menuupdater.delMenuItem(menuEntry[0][0], menuEntry[0][2], menuEntry[1], menuEntry[0][3])

	def menuUpdate(self):
		for menuEntry in self.menuEntries:
			menuupdater.addMenuItem(menuEntry[0][0], menuEntry[0][2], menuEntry[1], menuEntry[0][3])
	
	def runPlugin(self, plugin, session):
		try:
			exec "import " + self.prefix + plugin[2] + ".plugin"
			eval(self.prefix + plugin[2] + ".plugin").main(session)
		except:
			print "exec of plugin failed!"

plugins = PluginComponent()