modules know how to ask for a version number from the database

This commit is contained in:
Mike Bloy 2010-10-24 11:50:12 -05:00
parent 56d2847285
commit 6a67795b18
1 changed files with 19 additions and 0 deletions

View File

@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from ConfigParser import NoSectionError, NoOptionError
import inspect
import re
import sys
@ -290,12 +291,30 @@ class Module(object):
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")
See also db_module_registered, below.
"""
dbfile = self.config.get('dr.botzo', 'database')
conn = sqlite3.connect(dbfile)
return conn
def db_module_registered(self, modulename):
"""
ask the database for a version number for a module. Return that version
number if the module has registered, or None if not
"""
conn = self.get_db()
version = None
try:
cur = conn.cursor()
cur.execute("SELECT version FROM drbotzo_modules WHERE module = ?", modulename)
version = cur.fetchone()
if (version != None):
version = version[0]
finally: conn.close()
return version
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
"""
Do the primary thing this module was intended to do.