+ def hookexception(self, exc, handler):
+ self.exceptionhandlers.append((exc, handler))
+ def unhookexception(self, exc, handler):
+ self.exceptionhandlers.remove((exc, handler))
+ def hasexceptionhook(self, exc):
+ return any((True for x,h in self.exceptionhandlers if isinstance(exc, x)))
+ def getexceptionhook(self, exc):
+ return (h for x,h in self.exceptionhandlers if isinstance(exc, x))
+
+
+def dbsetup():
+ main.db = None
+ main.dbs = []
+ dbtype = cfg.get('erebus', 'dbtype', 'mysql')
+ if dbtype == 'mysql':
+ _dbsetup_mysql()
+ elif dbtype == 'sqlite':
+ _dbsetup_sqlite()
+ else:
+ main.log('*', '!', 'Unknown dbtype in config: %s' % (dbtype))
+
+def _dbsetup_mysql():
+ global db_api
+ import MySQLdb as db_api, MySQLdb.cursors
+ for i in range(cfg.get('erebus', 'num_db_connections', 2)-1):
+ main.dbs.append(db_api.connect(host=cfg.dbhost, user=cfg.dbuser, passwd=cfg.dbpass, db=cfg.dbname, cursorclass=MySQLdb.cursors.DictCursor))
+ main.db = db_api.connect(host=cfg.dbhost, user=cfg.dbuser, passwd=cfg.dbpass, db=cfg.dbname, cursorclass=MySQLdb.cursors.DictCursor)
+
+def _dbsetup_sqlite():
+ global db_api
+ import sqlite3 as db_api
+ for i in range(cfg.get('erebus', 'num_db_connections', 2)):
+ main.db = db_api.connect(cfg.dbhost)
+ main.db.row_factory = db_api.Row
+ main.db.isolation_level = None
+ main.dbs.append(main.db)