def __init__(self, config, client, munin): # Private variables self.notprefix = r"~|-|\." self.pubprefix = r"!" self.privprefix = "@" self.client = client self.munin = munin self.ctrl_list = {} self.config = config # database variables (also private) self.mod_dir = "mod" self.user = config.get("Database", "user") self.dbname = config.get("Database", "dbname") self.dsn = "user=%s dbname=%s" % (self.user, self.dbname) if config.has_option("Database", "password"): self.dsn += " password=%s" % config.get("Database", "password") if config.has_option("Database", "host"): self.dsn += " host=%s" % config.get("Database", "host") # database connection and cursor self.conn = psycopg.connect(self.dsn) self.conn.set_isolation_level(0) self.cursor = self.conn.cursor() self.galstatus = galstatus.galstatus(self.client, self.conn, self.cursor, config) # Necessary regexps (still private) self.welcomre = re.compile(r"\S+\s+001.*", re.I) # obey P self.pinvitere = re.compile(r"^:[email protected]\s+INVITE\s+\S+\s+:#(\S+)", re.I) # privmsg command regexes self.privmsgre = re.compile(r"^:(\S+)!(\S+)@(\S+)\s+PRIVMSG\s+(\S+)\s+:(.*)") self.ischannelre = re.compile(r"(#\S+)") self.pnickre = re.compile(r"(\S{2,15})\.users\.netgamers\.org") self.reg_controllers() self.commandre = re.compile(r"^(%s|%s|%s)(.*)\s*$" % (self.notprefix, self.pubprefix, self.privprefix)) self.loadmodre = re.compile(r"^loadmod\s+(\S+)") self.helpre = re.compile(r"^help(\s+(\S+))?") self.scanre = re.compile("http://[^/]+/showscan.pl\?scan_id=([0-9a-zA-Z]+)") self.scangrpre = re.compile("http://[^/]+/showscan.pl\?scan_grp=([0-9a-zA-Z]+)")
def load_mod(self, mod_name): try: if mod_name == "loadable": loadable = reload(sys.modules["loadable"]) self.reg_controllers() return None if mod_name == "scan": scan = reload(sys.modules["scan"]) return None if mod_name == "galstatus": galstatus = reload(sys.modules["galstatus"]) self.galstatus = galstatus.galstatus(self.client, self.conn, self.cursor, self.config) return None filename = os.path.join(self.mod_dir, mod_name + ".py") execfile(filename) self.ctrl_list[mod_name] = locals().get(mod_name)(self.cursor) except Exception, e: traceback.print_exc() return e.__str__()