add possibility to have menu entries from a plugin
[enigma2.git] / lib / python / Components / PluginComponent.py
index 095be3965ff81749b7cfa54825eada9353d05a76..4356456cb034c26a4312c433abebcf726c0b19b3 100644 (file)
@@ -1,16 +1,10 @@
 import os
+import traceback
 
 from Tools.Directories import *
+from Tools.Import import my_import
 from Plugins.Plugin import PluginDescriptor
 
-def my_import(name):
-       print name
-       mod = __import__(name)
-       components = name.split('.')
-       for comp in components[1:]:
-               mod = getattr(mod, comp)
-       return mod
-
 class PluginComponent:
        def __init__(self):
                self.plugins = {}
@@ -50,13 +44,19 @@ class PluginComponent:
                                path = directory_category + "/" + x
                                if os.path.isdir(path):
                                        if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
-                                               plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
+                                               try:
+                                                       plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
 
-                                               if not plugin.__dict__.has_key("Plugins"):
-                                                       print "Plugin %s doesn't have 'Plugin'-call." % (x)
-                                                       continue
+                                                       if not plugin.__dict__.has_key("Plugins"):
+                                                               print "Plugin %s doesn't have 'Plugin'-call." % (x)
+                                                               continue
 
-                                               plugins = plugin.Plugins(path=path)
+                                                       plugins = plugin.Plugins(path=path)
+                                               except Exception, exc:
+                                                       print "Plugin ", path, "failed to load:", exc
+                                                       traceback.print_exc(file=sys.stdout)
+                                                       print "skipping plugin."
+                                                       continue
 
                                                # allow single entry not to be a list
                                                if type(plugins) is not list:
@@ -87,7 +87,13 @@ class PluginComponent:
                        for p in self.plugins.get(x, [ ]):
                                res.append(p)
                return res
-       
+
+       def getPluginsForMenu(self, menuid):
+               res = [ ]
+               for p in self.getPlugins(PluginDescriptor.WHERE_SETUP):
+                       res += p(menuid)
+               return res
+
        def clearPluginList(self):
                self.pluginList = []
                self.plugins = {}