# This class is used to load plugins import sys from bt.message import write from bt.file import * class PluginLoader: def __init__(self): # Plugins are added to this array upon loading self.plugins = [] def clearPlugins(self): self.plugins = [] # Load plugins from a directory def loaddir(self, dir): exists = checkDir(dir) # Exit now if the directory doesn't exist if exists == False: return write("Loading plugins from " + dir, True) # Add the directory to our import path sys.path.append(dir) modlist = ls(dir) for mod in modlist: split = mod.rsplit('.',1) # Check for things we should not import if split[0]=="__init__": continue elif split[1]=="pyc": continue # Load the module into our module array write("Attempting to load "+mod, True) self.loadmod(split[0]) # Call with a module name to import # Adds the imported module to a list def loadmod(self,mod): __import__(mod) plugin = sys.modules[mod] plugin.__name__ = mod self.plugins += [plugin] # Load specific plugin def loadpath(self, path): write("Loading " + path)