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 reReadPluginList(self, directory, depth = 1):
38 print "re-reading plugin list"
39 self.clearPluginList()
40 self.readPluginList(directory=directory, depth=depth)
42 def readPluginList(self, directory, modules = [], depth = 1):
43 """enumerates plugins"""
45 directories = os.listdir(directory)
48 path = directory + x + "/"
49 if os.path.isdir(path):
50 if fileExists(path + "plugin.py"):
51 plugin = my_import('.'.join(["Plugins"] + modules + [x, "plugin"]))
53 if not plugin.__dict__.has_key("Plugins"):
54 print "Plugin %s doesn't have 'Plugin'-call." % (x)
57 plugins = plugin.Plugins()
59 # allow single entry not to be a list
60 if type(plugins) is not list:
67 open(path + "__init__.py", "a").close()
68 self.readPluginList(path, modules + [x], depth - 1)
70 def getPlugins(self, where):
71 """Get list of plugins in a specific category"""
73 if type(where) is not list:
77 for p in self.plugins.get(x, [ ]):
81 def clearPluginList(self):
86 for p in self.pluginList[:]:
89 plugins = PluginComponent()