3 from Tools.Directories import *
4 from Tools.Import import my_import
5 from Plugins.Plugin import PluginDescriptor
11 self.setPluginPrefix("Plugins.")
13 def setPluginPrefix(self, prefix):
16 def addPlugin(self, plugin):
17 self.pluginList.append(plugin)
18 for x in plugin.where:
19 self.plugins.setdefault(x, []).append(plugin)
20 if x == PluginDescriptor.WHERE_AUTOSTART:
23 def removePlugin(self, plugin):
24 self.pluginList.remove(plugin)
25 for x in plugin.where:
26 self.plugins[x].remove(plugin)
27 if x == PluginDescriptor.WHERE_AUTOSTART:
30 def readPluginList(self, directory):
31 """enumerates plugins"""
33 categories = os.listdir(directory)
38 directory_category = directory + c
39 if not os.path.isdir(directory_category):
41 open(directory_category + "/__init__.py", "a").close()
42 for x in os.listdir(directory_category):
43 path = directory_category + "/" + x
44 if os.path.isdir(path):
45 if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
46 plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
48 if not plugin.__dict__.has_key("Plugins"):
49 print "Plugin %s doesn't have 'Plugin'-call." % (x)
52 plugins = plugin.Plugins(path=path)
54 # allow single entry not to be a list
55 if type(plugins) is not list:
62 # build a diff between the old list of plugins and the new one
63 # internally, the "fnc" argument will be compared with __eq__
64 plugins_added = [p for p in new_plugins if p not in self.pluginList]
65 plugins_removed = [p for p in self.pluginList if p not in new_plugins]
67 for p in plugins_removed:
70 for p in plugins_added:
73 def getPlugins(self, where):
74 """Get list of plugins in a specific category"""
76 if type(where) is not list:
80 for p in self.plugins.get(x, [ ]):
84 def clearPluginList(self):
89 for p in self.pluginList[:]:
92 plugins = PluginComponent()