def __init__(self): logging.debug('Plugin manager initializing') # This will be set later, unable to activate plugins untill set self.config = None self.plugins = {} self.plugin_bases = {} for plugin_base in Plugin.__subclasses__(): plugin_name = plugin_base.__name__ self.plugin_bases[plugin_name] = plugin_base self.plugins[plugin_name] = [] logging.debug('Searching for plugins') plugins_found = self.find_plugins(Plugin.__subclasses__()) for i, plugin_base in enumerate(Plugin.__subclasses__()): plugin_type = plugin_base.__name__ for plugin in plugins_found[i]: self.plugins[plugin_type].append(plugin) # list of active plugins self.active = {} for key in self.plugins: self.active[key] = []
def testPluginReload(self): "Make sure the plugin classes are only loaded once." for i in range(1,5): self.factory.load_plugins() plugin_set = Set(Plugin.__subclasses__()) self.assertEquals(len(plugin_set), len(Plugin.__subclasses__()))
def load_plugins(): with open(__config_file__, "r") as fh: for line in fh: line = line.strip() if line.startswith("#") or line == "": continue # just load the whole shit... try: __import__(pluginPath+"."+line, globals(), locals(), [], -1) except NecessaryModuleNotFound as e: logger.critical("Failed loading plugin due to missing module: "+str(e)) except ApiKeyNotFoundException as e: logger.critical("Failed loading plugin due to missing API key: "+str(e)) except: logger.exception("Plugin loading failed") # as they are loaded in the order in the file we will have the same order in __subclasses__()... I hope for clazz in Plugin.__subclasses__(): # look at all functions of a class lets filter them first methods = filter(lambda x: type(x) == FunctionType, clazz.__dict__.values()) # now we check if the method is decorated by register for method in methods: if __criteria_key__ in method.__dict__: criterias = method.__dict__[__criteria_key__] for lang, regex in criterias.items(): if not lang in plugins: plugins[lang] = [] # yeah... save the regex, the clazz and the method, shit just got loaded... plugins[lang].append((regex, clazz, method))
def __init__(self): # load config self.config = ConfigParser.ConfigParser() if not self.config.read("config.ini"): print "Error: your config.ini could not be read" exit(1) # load plugins importdir.do("plugins", globals()) self.plugins = [ module(config=self.config) for module in Plugin.__subclasses__() ] # load required config self.server = self.config.get('IRC', 'server') self.port = int(self.config.get('IRC', 'port')) self.nick = self.config.get('IRC', 'nick') self.ircchan = self.config.get('IRC', 'ircchan').split(",") self.debugchan = self.config.get('IRC', 'debugchan') # optional config try: self.ignore = self.config.get('IRC', 'ignore').split(',') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): self.ignore = [] try: self.joindelay = int(self.config.get('IRC', 'joindelay')) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): self.joindelay = 0 self.irc = IRCBot(self.server, self.port, self.nick)
def __init__(self): ss = listdir(BASE_PATH+'/plugins') sys.path.insert(0, BASE_PATH+'/plugins') for s in ss: if (splitext(s)[1] == '.py'): __import__(splitext(s)[0], None, None, ['']) for plugin in Plugin.__subclasses__(): p = plugin() if p.keyword == 'default': self.default_plugin = p if p.controlled: self.plugins.append(p) else: p.start() return
def __init__(self): # load config self.config = ConfigParser.ConfigParser() self.translations = ConfigParser.ConfigParser() if not self.config.read("config.ini"): print "Error: your config.ini could not be read" exit(1) if not self.translations.read("language.ini"): print "Error: your language.ini could not be read" exit(1) # load plugins importdir.do("plugins", globals()) self.plugins = [module(config=self.config) for module in Plugin.__subclasses__()] # load required config self.server=self.config.get('IRC','server') self.port=int(self.config.get('IRC', 'port')) self.nick=self.config.get('IRC', 'nick') self.ircchan=self.config.get('IRC', 'ircchan').split(",") self.debugchan=self.config.get('IRC', 'debugchan') self.useragent=self.config.get('HTTP', 'useragent') self.language=self.config.get('Language','language') self.spacestatus=self.config.get('SpaceStatus', 'url') try: self.ignore=self.config.get('IRC','ignore').split(',') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): self.ignore = [] # load translation keys # load optional config try: self.nickservpassword=self.config.get('IRC', 'nickservpassword') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): pass self.identified = False self.httpregex = re.compile(r'https?://') self.irc = IRCBot(self.server, self.port, self.nick)
def load_plugins(): with open(config_file, "r") as fh: for line in fh: line = line.strip() if line.startswith("#") or line == "": continue # just load the whole shit... __import__(pluginPath+"."+line, globals(), locals(), [], -1) # as they are loaded in the order in the file we will have the same order in __subclasses__()... I hope for clazz in Plugin.__subclasses__(): # look at all functions of a class lets filter them first methods = filter(lambda x: type(x) == FunctionType, clazz.__dict__.values()) # now we check if the method is decorated by register for method in methods: if __criteria_key__ in method.__dict__: criterias = method.__dict__[__criteria_key__] for lang, regex in criterias.items(): if not lang in plugins: plugins[lang] = [] # yeah... save the regex, the clazz and the method, shit just got loaded... plugins[lang].append((regex, clazz, method))
def __init__(self): # load config config = ConfigParser.ConfigParser() if not config.read("config.ini"): print "Error: your config.ini could not be read" exit(1) # load plugins importdir.do("plugins", globals()) self.plugins = [module() for module in Plugin.__subclasses__()] self.server=config.get('IRC','server') self.port=int(config.get('IRC', 'port')) self.nick=config.get('IRC', 'nick') self.ircchan=config.get('IRC', 'ircchan') self.debugchan=config.get('IRC', 'debugchan') self.useragent=config.get('HTTP', 'useragent') self.site = wiki.Wiki(config.get('MediaWiki', 'wikiapiurl')) self.site.login(config.get('MediaWiki', 'user'), config.get('MediaWiki', 'password')) self.httpregex=re.compile(r'https?://') self.irc = IRCBot(self.server, self.port, self.nick)
def __init__(self): # load config config = ConfigParser.ConfigParser() if not config.read("config.ini"): print "Error: your config.ini could not be read" exit(1) # load plugins importdir.do("plugins", globals()) self.plugins = [module() for module in Plugin.__subclasses__()] self.server = config.get('IRC', 'server') self.port = int(config.get('IRC', 'port')) self.nick = config.get('IRC', 'nick') self.ircchan = config.get('IRC', 'ircchan') self.debugchan = config.get('IRC', 'debugchan') self.useragent = config.get('HTTP', 'useragent') self.site = wiki.Wiki(config.get('MediaWiki', 'wikiapiurl')) self.site.login(config.get('MediaWiki', 'user'), config.get('MediaWiki', 'password')) self.httpregex = re.compile(r'https?://') self.irc = IRCBot(self.server, self.port, self.nick)