]> jfr.im git - erebus.git/blobdiff - erebus.py
help bugfix
[erebus.git] / erebus.py
index 190c4ba2301b0eeb39efe9cb83a7982717b8f150..90e13898fe077e47167360f4b80d4c17ac7144a7 100644 (file)
--- 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()))