5 from Tools.Directories import *
6 from Tools.Import import my_import
7 from Plugins.Plugin import PluginDescriptor
13 self.setPluginPrefix("Plugins.")
15 def setPluginPrefix(self, prefix):
18 def addPlugin(self, plugin):
19 self.pluginList.append(plugin)
20 for x in plugin.where:
21 self.plugins.setdefault(x, []).append(plugin)
22 if x == PluginDescriptor.WHERE_AUTOSTART:
25 def removePlugin(self, plugin):
26 self.pluginList.remove(plugin)
27 for x in plugin.where:
28 self.plugins[x].remove(plugin)
29 if x == PluginDescriptor.WHERE_AUTOSTART:
32 def readPluginList(self, directory):
33 """enumerates plugins"""
35 categories = os.listdir(directory)
40 directory_category = directory + c
41 if not os.path.isdir(directory_category):
43 open(directory_category + "/__init__.py", "a").close()
44 for x in os.listdir(directory_category):
45 path = directory_category + "/" + x
46 if os.path.isdir(path):
47 if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
49 plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
51 if not plugin.__dict__.has_key("Plugins"):
52 print "Plugin %s doesn't have 'Plugin'-call." % (x)
55 plugins = plugin.Plugins(path=path)
56 except Exception, exc:
57 print "Plugin ", path, "failed to load:", exc
58 traceback.print_exc(file=sys.stdout)
59 print "skipping plugin."
62 # allow single entry not to be a list
63 if type(plugins) is not list:
70 # build a diff between the old list of plugins and the new one
71 # internally, the "fnc" argument will be compared with __eq__
72 plugins_added = [p for p in new_plugins if p not in self.pluginList]
73 plugins_removed = [p for p in self.pluginList if p not in new_plugins]
75 for p in plugins_removed:
78 for p in plugins_added:
81 def getPlugins(self, where):
82 """Get list of plugins in a specific category"""
84 if type(where) is not list:
88 for p in self.plugins.get(x, [ ]):
92 def getPluginsForMenu(self, menuid):
94 for p in self.getPlugins(PluginDescriptor.WHERE_SETUP):
98 def clearPluginList(self):
103 for p in self.pluginList[:]:
106 plugins = PluginComponent()