3 from Tools.Directories import *
4 from Plugins.Plugin import PluginDescriptor
9 components = name.split('.')
10 for comp in components[1:]:
11 mod = getattr(mod, comp)
14 class PluginComponent:
18 self.setPluginPrefix("Plugins.")
20 def setPluginPrefix(self, prefix):
23 def addPlugin(self, plugin):
24 self.pluginList.append(plugin)
25 for x in plugin.where:
26 self.plugins.setdefault(x, []).append(plugin)
27 if x == PluginDescriptor.WHERE_AUTOSTART:
30 def removePlugin(self, plugin):
31 self.pluginList.remove(plugin)
32 for x in plugin.where:
33 self.plugins[x].remove(plugin)
34 if x == PluginDescriptor.WHERE_AUTOSTART:
37 def readPluginList(self, directory, modules = [], depth = 1):
38 """enumerates plugins"""
40 directories = os.listdir(directory)
43 path = directory + x + "/"
44 if os.path.isdir(path):
45 if fileExists(path + "plugin.py"):
46 plugin = my_import('.'.join(["Plugins"] + modules + [x, "plugin"]))
48 if not plugin.__dict__.has_key("Plugins"):
49 print "Plugin %s doesn't have 'Plugin'-call." % (x)
52 plugins = plugin.Plugins()
54 # allow single entry not to be a list
55 if type(plugins) is not list:
62 open(path + "__init__.py", "w").close()
63 self.readPluginList(path, modules + [x], depth - 1)
65 def getPlugins(self, where):
66 """Get list of plugins in a specific category"""
68 if type(where) is not list:
72 for p in self.plugins.get(x, [ ]):
76 def clearPluginList(self):
80 for p in self.pluginList[:]:
83 plugins = PluginComponent()