add a tuxbox plugins plugin to prepare loading of tuxbox plugins when the c++ part...
[enigma2.git] / lib / python / Components / PluginComponent.py
index 0b4070218b5462a65a3fb06e633c04d1f81f4aea..960043d68d98c624d6aacc626670032e94ee182a 100644 (file)
@@ -12,7 +12,7 @@ class PluginComponent:
        def setPluginPrefix(self, prefix):
                self.prefix = prefix
 
-       def getPluginList(self):
+       def getPluginList(self, runAutostartPlugins=False, runAutoendPlugins=False):
                list = []
                dir = os.listdir(resolveFilename(SCOPE_PLUGINS))
                self.menuDelete()
@@ -20,21 +20,38 @@ class PluginComponent:
 
                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
+                       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
        
-                                       list.append((picturepath, pluginname , x))
+                                               for y in range(len(plugins)):
+                                                       if len(plugins[y]) < 4:
+                                                               list.append((path + picturepaths[y], plugins[y][0] , x, plugins[y][1], plugins[y][2], None))
+                                                       else:
+                                                               list.append((path + picturepaths[y], plugins[y][0] , x, plugins[y][1], plugins[y][2], plugins[y][3]))
+                                               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
        
@@ -48,8 +65,11 @@ class PluginComponent:
        
        def runPlugin(self, plugin, session):
                try:
-                       exec "import " + self.prefix + plugin[2] + ".plugin"
-                       eval(self.prefix + plugin[2] + ".plugin").main(session)
+                       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!"