__author__="bjschuma" __date__ ="$Dec 8, 2009 8:40:36 AM$" import sys from bt.message import write class Manager: def __init__(self): write("Creating plugin manager", True) self.enabled = [] # Map plugin name to dictionary self.disabled = [] def addPlugins(self, plugins): # Add each plugin to the disabled list for plugin in plugins: write("Adding plugin: " + str(plugin), True) self.disabled += [plugin] # If we are adding a core plugin, activate it right away if(plugin.__type__=="core"): self.enablePlugin(plugin.__name__) # Move plugin from old[index] to new # Return the plugin def movePlugin(self, index, old, new): plugin = old.pop(index) index = len(new) new += [plugin] return plugin,index # Disable a plugin, return index of disabled plugin def disablePlugin(self,name): index = self.findPlugin(name, self.enabled) if index > -1: write("Disabling plugin: "+name) plugin,index = self.movePlugin(index, self.enabled, self.disabled) plugin.close() return index # Move a plugin to the enabled list, return number of plugins enabled def enablePlugin(self,name): index = self.findPlugin(name, self.disabled) if index > -1: write("Enabling plugin: "+name,True) plugin,index = self.movePlugin(index, self.disabled, self.enabled) plugin.open() return True # Return first location where plugin.__name__ == name def findPlugin(self,name,array): write("Finding plugin: "+name,True) for i in range(len(array)): if array[i].__name__ == name: return i return -1 # Disable the plugin, reload it, reenable it def reloadPlugin(self,name): # Check if plugin has been loaded if (name in sys.modules) == False: write("Plugin not loaded: "+name, True) return reenable = self.disablePlugin(name) #import sys #write(sys.modules["example"]) #return #reenable = self.disablePlugin(name) #index = self.findPlugin(name, self.disabled) #write("Reloading plugin: "+name) #plugin = self.disabled[index] #print plugin #reload(plugin) # Only reenable if a plugin was disabled #if reenable == True: # self.enablePlugin(name) global manager manager = Manager()