# This class is used to load plugins import sys from bt.message import * from bt.file import * class PluginLoader: def __init__(self): # Plugins are added to this array upon loading self.plugins = [] def clearPlugins(self): self.plugins = [] def getPlugins(self): plugs = self.plugins self.clearPlugins() return plugs # Load plugins from a directory def loaddir(self, dir): write("Loading plugins from " + dir, 1) # Add the directory to our import path sys.path.append(dir) modlist = ls(dir) # ls will return false if the directory doesn't exst. # We check this here to avoid checking if the dir exists twice if modlist == False: write("Directory does not exist: "+dir) return for mod in modlist: split = mod.rsplit('.',1) # Check for things we should not import if split[0]=="__init__": continue elif len(split)==1: continue elif split[1]=="pyc": continue # Load the module into our module array write("Attempting to load "+mod, 2) #try: self.loadmod(split[0], dir) #except: # error("Error loading "+mod) # Call with a module name to import and path to plugin # Adds the imported module to a list def loadmod(self,mod,path): __import__(mod) plugin = sys.modules[mod].Plugin() plugin.name = mod #plugin.path = path self.plugins += [plugin] # Load specific plugin def loadpath(self, path): write("Loading " + path) load = PluginLoader()