1 from os import path as os_path, listdir as os_listdir
2 from traceback import print_exc
5 from Tools.Directories import fileExists
6 from Tools.Import import my_import
7 from Plugins.Plugin import PluginDescriptor
13 self.setPluginPrefix("Plugins.")
16 def setPluginPrefix(self, prefix):
19 def addPlugin(self, plugin):
20 self.pluginList.append(plugin)
21 for x in plugin.where:
22 self.plugins.setdefault(x, []).append(plugin)
23 if x == PluginDescriptor.WHERE_AUTOSTART:
26 def removePlugin(self, plugin):
27 self.pluginList.remove(plugin)
28 for x in plugin.where:
29 self.plugins[x].remove(plugin)
30 if x == PluginDescriptor.WHERE_AUTOSTART:
33 def readPluginList(self, directory):
34 """enumerates plugins"""
36 categories = os_listdir(directory)
41 directory_category = directory + c
42 if not os_path.isdir(directory_category):
44 open(directory_category + "/__init__.py", "a").close()
45 for pluginname in os_listdir(directory_category):
46 path = directory_category + "/" + pluginname
47 if os_path.isdir(path):
48 if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
50 plugin = my_import('.'.join(["Plugins", c, pluginname, "plugin"]))
52 if not plugin.__dict__.has_key("Plugins"):
53 print "Plugin %s doesn't have 'Plugin'-call." % (pluginname)
56 plugins = plugin.Plugins(path=path)
57 except Exception, exc:
58 print "Plugin ", c + "/" + pluginname, "failed to load:", exc
59 print_exc(file=stdout)
60 print "skipping plugin."
61 self.warnings.append( (c + "/" + pluginname, str(exc)) )
64 # allow single entry not to be a list
65 if type(plugins) is not list:
72 # build a diff between the old list of plugins and the new one
73 # internally, the "fnc" argument will be compared with __eq__
74 plugins_added = [p for p in new_plugins if p not in self.pluginList]
75 plugins_removed = [p for p in self.pluginList if p not in new_plugins]
77 for p in plugins_removed:
80 for p in plugins_added:
83 def getPlugins(self, where):
84 """Get list of plugins in a specific category"""
86 if type(where) is not list:
90 for p in self.plugins.get(x, [ ]):
94 def getPluginsForMenu(self, menuid):
96 for p in self.getPlugins(PluginDescriptor.WHERE_SETUP):
100 def clearPluginList(self):
105 for p in self.pluginList[:]:
108 def resetWarnings(self):
111 plugins = PluginComponent()