4 from Tools.Directories import *
5 from Tools.Import import my_import
6 from Plugins.Plugin import PluginDescriptor
12 self.setPluginPrefix("Plugins.")
14 def setPluginPrefix(self, prefix):
17 def addPlugin(self, plugin):
18 self.pluginList.append(plugin)
19 for x in plugin.where:
20 self.plugins.setdefault(x, []).append(plugin)
21 if x == PluginDescriptor.WHERE_AUTOSTART:
24 def removePlugin(self, plugin):
25 self.pluginList.remove(plugin)
26 for x in plugin.where:
27 self.plugins[x].remove(plugin)
28 if x == PluginDescriptor.WHERE_AUTOSTART:
31 def readPluginList(self, directory):
32 """enumerates plugins"""
34 categories = os.listdir(directory)
39 directory_category = directory + c
40 if not os.path.isdir(directory_category):
42 open(directory_category + "/__init__.py", "a").close()
43 for x in os.listdir(directory_category):
44 path = directory_category + "/" + x
45 if os.path.isdir(path):
46 if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
48 plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
50 if not plugin.__dict__.has_key("Plugins"):
51 print "Plugin %s doesn't have 'Plugin'-call." % (x)
54 plugins = plugin.Plugins(path=path)
55 except Exception, exc:
56 print "Plugin ", path, "failed to load:", exc
57 traceback.print_exc(file=sys.stdout)
58 print "skipping plugin."
61 # allow single entry not to be a list
62 if type(plugins) is not list:
69 # build a diff between the old list of plugins and the new one
70 # internally, the "fnc" argument will be compared with __eq__
71 plugins_added = [p for p in new_plugins if p not in self.pluginList]
72 plugins_removed = [p for p in self.pluginList if p not in new_plugins]
74 for p in plugins_removed:
77 for p in plugins_added:
80 def getPlugins(self, where):
81 """Get list of plugins in a specific category"""
83 if type(where) is not list:
87 for p in self.plugins.get(x, [ ]):
91 def getPluginsForMenu(self, menuid):
93 for p in self.getPlugins(PluginDescriptor.WHERE_SETUP):
97 def clearPluginList(self):
102 for p in self.pluginList[:]:
105 plugins = PluginComponent()