X-Git-Url: https://jfr.im/git/erebus.git/blobdiff_plain/a8553c45336be4a753376127fcad5c9034cae707..b367d0c5869793453f81614d320a65b169926794:/erebus.py diff --git a/erebus.py b/erebus.py index 190c4ba..90e1389 100644 --- a/erebus.py +++ b/erebus.py @@ -3,11 +3,11 @@ # Erebus IRC bot - Author: John Runyon # main startup code -import os, sys, select, MySQLdb, MySQLdb.cursors, time, random +import os, sys, select, MySQLdb, MySQLdb.cursors, time, random, gc import bot, config, ctlmod class Erebus(object): #singleton to pass around - APIVERSION = 1 + APIVERSION = 2 RELEASE = 0 bots = {} @@ -207,6 +207,9 @@ class Erebus(object): #singleton to pass around def log(self, source, level, message): print "%09.3f %s [%s] %s" % (time.time() % 100000, source, level, message) + def getuserbyauth(self, auth): + return [u for u in self.users.itervalues() if u.auth == auth.lower()] + #bind functions def hook(self, word, handler): try: @@ -250,6 +253,11 @@ class Erebus(object): #singleton to pass around class MyCursor(MySQLdb.cursors.DictCursor): def execute(self, *args, **kwargs): + if 'norecurse' in kwargs: + norecurse = kwargs['norecurse'] + del kwargs['norecurse'] + else: + norecurse = False main.log("[SQL]", "?", "MyCursor.execute(self, %s, %s)" % (', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs]))) # print "%09.3f [SQL] [#] MyCursor.execute(self, %s, %s)" % (time.time() % 100000, ', '.join([repr(i) for i in args]), ', '.join([str(key)+"="+repr(kwargs[key]) for key in kwargs])) try: @@ -257,7 +265,9 @@ class MyCursor(MySQLdb.cursors.DictCursor): except MySQLdb.MySQLError as e: main.log("[SQL]", "!", "MySQL error! %r" % (e)) # print "%09.3f [SQL] [!] MySQL error! %r" % (time.time() % 100000, e) - dbsetup() + if not norecurse: + dbsetup() + return self.execute(norecurse=True, *args, **kwargs) return False return True @@ -269,7 +279,10 @@ def dbsetup(): def setup(): global cfg, main - cfg = config.Config('bot.config') + cfg = config.setup('bot.config') + + if int(cfg.get('debug', 'gc', default=0)) == 1: + gc.set_debug(gc.DEBUG_LEAK) pidfile = open(cfg.pidfile, 'w') pidfile.write(str(os.getpid()))