create the database if it doesn't exist, on startup
This commit is contained in:
parent
240612fecf
commit
48427ecd21
27
dr.botzo.py
27
dr.botzo.py
|
@ -22,6 +22,7 @@ import re
|
|||
import socket
|
||||
import sys
|
||||
import inspect
|
||||
import sqlite3
|
||||
|
||||
from extlib import irclib
|
||||
|
||||
|
@ -103,6 +104,32 @@ except NoOptionError as e:
|
|||
# load additional options
|
||||
irclib.DEBUG = config.getboolean('dr.botzo', 'debug')
|
||||
|
||||
try:
|
||||
# make sure we can initialize the database, if such a thing is
|
||||
# called for in the config file
|
||||
dbfile = config.get('dr.botzo', 'database')
|
||||
conn = sqlite3.connect(dbfile)
|
||||
try:
|
||||
query = """
|
||||
SELECT COUNT(*)
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table' AND name = 'drbotzo_modules'
|
||||
"""
|
||||
row = conn.execute(query).fetchone()
|
||||
if row[0] == 0:
|
||||
# need to create the drbotzo_modules table
|
||||
query = """
|
||||
CREATE TABLE drbotzo_modules (
|
||||
module TEXT,
|
||||
version INTEGER
|
||||
)
|
||||
"""
|
||||
conn.execute(query)
|
||||
conn.commit()
|
||||
finally: conn.close()
|
||||
except NoOptionError: pass # if the config file has no db property, assume that
|
||||
except NoSectionError: pass # the database doesn't need to exist
|
||||
|
||||
# start up the IRC bot
|
||||
|
||||
# create IRC and server objects and connect
|
||||
|
|
Loading…
Reference in New Issue