2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
__author__="bjschuma"
|
|
|
|
__date__ ="$Dec 8, 2009 8:40:36 AM$"
|
|
|
|
|
|
|
|
import sys
|
|
|
|
from bt.message import write
|
2009-12-18 00:07:45 -05:00
|
|
|
import loader
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
class Manager:
|
|
|
|
def __init__(self):
|
|
|
|
write("Creating plugin manager", True)
|
2009-12-18 00:07:45 -05:00
|
|
|
# Map the plugin name to a dictionary
|
|
|
|
self.enabled = dict()
|
|
|
|
self.disabled = dict()
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
def addPlugins(self, plugins):
|
|
|
|
# Add each plugin to the disabled list
|
|
|
|
for plugin in plugins:
|
|
|
|
write("Adding plugin: " + str(plugin), True)
|
2009-12-18 00:07:45 -05:00
|
|
|
self.disabled[plugin.name] = plugin
|
2009-12-17 22:30:27 -05:00
|
|
|
# If we are adding a core plugin, activate it right away
|
2009-12-18 00:07:45 -05:00
|
|
|
if(plugin.type=="core"):
|
|
|
|
self.enablePlugin(plugin.name)
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
2009-12-18 00:07:45 -05:00
|
|
|
# Move plugin from old[name] to new[name]
|
2009-12-17 22:30:27 -05:00
|
|
|
# Return the plugin
|
2009-12-18 00:07:45 -05:00
|
|
|
def movePlugin(self, name, old, new):
|
|
|
|
plugin = old.pop(name)
|
|
|
|
new[name] = plugin
|
|
|
|
return plugin
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
2009-12-18 00:07:45 -05:00
|
|
|
# Disable a plugin
|
|
|
|
# Returns true if there was a plugin to disable, false otherwise
|
2009-12-17 22:30:27 -05:00
|
|
|
def disablePlugin(self,name):
|
2009-12-18 00:07:45 -05:00
|
|
|
if (name in self.enabled) == True:
|
2009-12-17 22:30:27 -05:00
|
|
|
write("Disabling plugin: "+name)
|
2009-12-18 00:07:45 -05:00
|
|
|
plugin = self.movePlugin(name, self.enabled, self.disabled)
|
2009-12-17 22:30:27 -05:00
|
|
|
plugin.close()
|
2009-12-18 00:07:45 -05:00
|
|
|
return True
|
|
|
|
return False
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
2009-12-18 00:07:45 -05:00
|
|
|
# Move a plugin to the enabled list
|
|
|
|
# Returns true if a plugin was enabled, false otherwise
|
2009-12-17 22:30:27 -05:00
|
|
|
def enablePlugin(self,name):
|
2009-12-18 00:07:45 -05:00
|
|
|
#index = self.findPlugin(name, self.disabled)
|
|
|
|
#if index > -1:
|
|
|
|
if (name in self.disabled) == True:
|
2009-12-17 22:30:27 -05:00
|
|
|
write("Enabling plugin: "+name,True)
|
2009-12-18 00:07:45 -05:00
|
|
|
plugin = self.movePlugin(name, self.disabled, self.enabled)
|
2009-12-17 22:30:27 -05:00
|
|
|
plugin.open()
|
2009-12-18 00:07:45 -05:00
|
|
|
return True
|
|
|
|
return False
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
# 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
|
2009-12-18 00:07:45 -05:00
|
|
|
# Disable the plugin and pop from sys.modules
|
2009-12-17 22:30:27 -05:00
|
|
|
reenable = self.disablePlugin(name)
|
2009-12-18 00:07:45 -05:00
|
|
|
reload(self.disabled[name])
|
|
|
|
if reenable == True:
|
|
|
|
self.enablePlugin(name)
|
2009-12-17 22:30:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
global manager
|
|
|
|
manager = Manager()
|