5315d3d94c68c0dd630951eed9406092bca278c6
[enigma2.git] / lib / python / Components / PluginComponent.py
1 import os
2
3 from Tools.Directories import *
4 from Screens.Menu import menuupdater
5 #import Plugins
6
7 class PluginComponent:
8         def __init__(self):
9                 self.plugins = []
10                 self.setPluginPrefix("Plugins.")
11                 self.menuEntries = []
12                 
13         def setPluginPrefix(self, prefix):
14                 self.prefix = prefix
15
16         def getPluginList(self):
17                 list = []
18                 dir = os.listdir("/usr/lib/enigma2/python/Plugins/")
19                 self.menuDelete()
20                 self.menuEntries = []
21                 for x in dir:
22                         if x[-3:] == ".py" and x[:-3] != "__init__":
23                                 print "trying to import " + self.prefix + x[:-3]
24                                 exec "import " + self.prefix + x[:-3]
25                                 picturepath = eval(self.prefix + x[:-3]).getPicturePath()
26                                 pluginname = eval(self.prefix + x[:-3]).getPluginName()
27                                 try:
28                                         for menuEntry in eval(self.prefix + x[:-3]).getMenuRegistrationList():
29                                                 self.menuEntries.append([menuEntry, self.prefix + x[:-3]])
30                                 except:
31                                         pass
32
33                                 list.append((picturepath, pluginname , x[:-3]))
34                 self.menuUpdate()
35                 return list
36         
37         def menuDelete(self):
38                 for menuEntry in self.menuEntries:
39                         menuupdater.delMenuItem(menuEntry[0][0], menuEntry[0][2], menuEntry[1], menuEntry[0][3])
40
41         def menuUpdate(self):
42                 for menuEntry in self.menuEntries:
43                         menuupdater.addMenuItem(menuEntry[0][0], menuEntry[0][2], menuEntry[1], menuEntry[0][3])
44         
45         def runPlugin(self, plugin, session):
46                 try:
47                         exec "import " + self.prefix + plugin[2]
48                         eval(self.prefix + plugin[2]).main(session)
49                 except:
50                         print "exec of plugin failed!"
51
52 plugins = PluginComponent()