database connection grabbing for Modules

This commit is contained in:
Mike Bloy 2010-10-24 09:46:41 -05:00
parent 40ab270324
commit 240612fecf
1 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,7 @@ from ConfigParser import NoSectionError, NoOptionError
import inspect
import re
import sys
import sqlite3
from extlib import irclib
@ -281,6 +282,20 @@ class Module(object):
self.server._handle_event(event)
def get_db(self):
"""
Get a database connection to sqlite3. Once grabbed, it should be closed
when work is done. Modules that need a database connection should
test for and create (or, eventually, alter) required table structure
in their __init__ IF that structure does not already exist. Well-behaved
modules should use a prefix in their table names (eg "karma_log" rather
than "log")
"""
dbfile = self.config.get('dr.botzo', 'database')
conn = sqlite3.connect(dbfile)
return conn
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""
Do the primary thing this module was intended to do.