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):
38 """enumerates plugins"""
40 categories = os.listdir(directory)
45 directory_category = directory + c
46 if not os.path.isdir(directory_category):
48 open(directory_category + "/__init__.py", "a").close()
49 for x in os.listdir(directory_category):
50 path = directory_category + "/" + x
51 if os.path.isdir(path):
52 if fileExists(path + "/plugin.pyc") or fileExists(path + "/plugin.py"):
53 plugin = my_import('.'.join(["Plugins", c, x, "plugin"]))
55 if not plugin.__dict__.has_key("Plugins"):
56 print "Plugin %s doesn't have 'Plugin'-call." % (x)
59 plugins = plugin.Plugins(path=path)
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 clearPluginList(self):
96 for p in self.pluginList[:]:
99 plugins = PluginComponent()