cas | 5 +---- cas-admin | 2 +- cas.conf | 11 ++--------- lib/cas/db.py | 46 +++++++++++++++++++++++++++++++--------------- 4 files changed, 35 insertions(+), 29 deletions(-)
New commits: commit 31c1d943ca61c8ddf0dc0b9d24ddbc7f464e8a0b Author: Adam Stokes adam.stokes@gmail.com Date: Tue Mar 31 13:13:07 2009 -0400
- more db changes
diff --git a/cas b/cas index e255e5e..0dac60c 100755 --- a/cas +++ b/cas @@ -42,10 +42,7 @@ WORKDIRECTORY = config.get("settings","workDirectory") DEBUGLEVEL = config.get("settings","debugLevel") SMTPHOST = config.get("settings", "mailServer") # Read database parameters -CASDB_CONF = {'dbhost': config.get("database","dbhost"), - 'dbuser': config.get("database","dbuser"), - 'dbpass': config.get("database","dbpass"), - 'dbname': config.get("database","dbname")} +DATABASE = config.get("settings", "database")
# Check for some advanced configurations # Test to see if we provide a 32bit crash binary diff --git a/cas-admin b/cas-admin index e394c9b..7fbc538 100755 --- a/cas-admin +++ b/cas-admin @@ -75,7 +75,7 @@ class CasDatabaseHandler(object): count = 0 """ Build database out in the form of RPM - [( DebugKernel, Timestamp), - ( DebugKernel2, Timestamp2)] +' ( DebugKernel2, Timestamp2)] """ for x in rpms: if not self.rpmExist(x): diff --git a/cas.conf b/cas.conf index 5b8808a..2b17e34 100644 --- a/cas.conf +++ b/cas.conf @@ -33,15 +33,8 @@ purgeLimit=90 # whenever cas-admin is run autoPurge=False
-[database] -# database connection info (mysql only) -# TODO: perhaps add orm support for multiple backends? -# A database needs to be manually created -# $ mysqladmin -uroot -predhat create $dbname -dbname='casdb' -dbhost='localhost' -dbuser='root' -dbpass='redhat' +# database connection info +database='/var/db/cas/cas.db'
[advanced] # if running a x86_64 system and wish to analyze 32bit diff --git a/lib/cas/db.py b/lib/cas/db.py index 57313d2..5e9ef7c 100644 --- a/lib/cas/db.py +++ b/lib/cas/db.py @@ -1,38 +1,54 @@ -import MySQLdb +import os +import sys + +if sys.version_info[:2] > (2,4): + try: + import sqlite3 as sqlite + except ImportError: + import sqlite
class CasStorageException(Exception): pass
class CasStorage(object): - def __init__(self, sql_server, username, password, database): + def __init__(self, database): """ setup database connection and return db cursor for traversing database """ self.db = database - self.sql_server = sql_server - self.username = username - self.password = password + self.conn = None self.cursor = None
+ def buildTable(self): + self.cursor.execute('''create table cas_jobs +(date text, submitter text, corepath text, debugpath text, +server text) + +create table debuginfo (rpm text) + +create table timestamp (debuginfo integer, debugpath text, timestamp text)''') + self.conn.commit() + return + def connect(self): """ execute connection """ try: - db_connect = MySQLdb.connect(host=self.sql_server, - user=self.username, - passwd=self.password, - db=self.db) - self.cursor = db_connect.cursor() - except OperationalError, e: - raise CasStorageException(e) + if not os.path.isfile(self.db): + # build out sql table + self.buildTable() + self.conn = sqlite.connect(self.db) + self.cursor = self.conn.cursor() + except: + raise CasStorageException('Cannot connect to database') return
def getAllJobs(self): """ all jobs """ self.cursor.execute("SELECT * FROM cas_jobs") - return self.cursor.fetchall() + return self.cursor
def getJobById(self, id): """ single job """ - self.cursor.execute("SELECT * FROM cas_jobs where id=%d" % (id,)) - return self.cursor.fetchone() + self.cursor.execute("SELECT * FROM cas_jobs where id=?", id) + return self.cursor
def getJobRange(self, days): """ provides jobs based on creation date from