cas-admin | 37 +++++++++++++++++-------------------
lib/cas/db.py | 59 +++++++++++++++++++++++++++++++++-------------------------
2 files changed, 52 insertions(+), 44 deletions(-)
New commits:
commit ca2d964a91f173a0accb3cdaceec24108f1ef119
Author: Adam Stokes <adam.stokes(a)gmail.com>
Date: Tue Apr 14 11:18:56 2009 -0400
- implementing first stages of db interaction within cas-admin
- updated database methods
diff --git a/cas-admin b/cas-admin
index 1c53ea7..b2d5f84 100755
--- a/cas-admin
+++ b/cas-admin
@@ -63,26 +63,25 @@ class CasDatabaseHandler(object):
self.casLog.status("(found) %-5d kernel(s)" % (count,))
count = count + 1
# query database for debuginfo rpms
- rpms = self.db.getDebuginfoRPM()
+ rpms = self.db.getAllDebuginfoRPM()
for id, rpm in rpms:
- if not self.rpmExist(rpm):
- # temporary storage path in form of DEBUGS/COUNT
- dst = os.path.join(DEBUGS, str(count))
- rpmTool = RPMBase()
- self.casLog.status("(extracting) %-50s" % (rpm))
- results = rpmTool.extract(rpm, dst)
- # Sort through extracted debug for each type
- # e.g. hugemem, PAE, smp, largesmp
- for item in results:
- vmlinux = item.strip()
- stamper = CoreBase()
- debugKernel = os.path.normpath(vmlinux)
- timestamp = stamper.timestamp(debugKernel)
- # add rpm id, debug, timestamp to database
- self.db.addTimestamp(id, debugKernel, timestamp)
- self.util.save(self.rpmDB, RPMS)
- # Cleanup extracted debugs
- rmtree(dst)
+ # temporary storage path in form of DEBUGS/COUNT
+ dst = os.path.join(DEBUGS, str(count))
+ rpmTool = RPMBase()
+ self.casLog.status("(extracting) %-50s" % (rpm))
+ results = rpmTool.extract(rpm, dst)
+ # Sort through extracted debug for each type
+ # e.g. hugemem, PAE, smp, largesmp
+ for item in results:
+ vmlinux = item.strip()
+ stamper = CoreBase()
+ debugKernel = os.path.normpath(vmlinux)
+ timestamp = stamper.timestamp(debugKernel)
+ # add rpm id, debug, timestamp to database
+ self.db.addTimestamp(id, debugKernel, timestamp)
+ self.util.save(self.rpmDB, RPMS)
+ # Cleanup extracted debugs
+ rmtree(dst)
return
class CasServerHandler(object):
diff --git a/lib/cas/db.py b/lib/cas/db.py
index e9b13e7..b0478a6 100644
--- a/lib/cas/db.py
+++ b/lib/cas/db.py
@@ -17,57 +17,66 @@ class CasStorage(object):
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 (debug_id integer primary key autoincrement, rpm text)
+ def connect(self):
+ """ execute connection """
+ try:
+ self.conn = sqlite.connect(self.db)
+ self.cursor = self.conn.cursor()
+ except:
+ raise CasStorageException('Cannot connect to database')
+ return
- create table timestamp (timestamp_id integer primary key autoincrement,
- debugpath text, timestamp text, debug_id integer)''')
+ def commit(self):
self.conn.commit()
return
+ def buildTable(self):
+ self.cursor.execute("create table cas_jobs (job_id integer primary key
autoincrement, date text, submitter text, corepath text, debug_id integer, server_id
integer, iterations integer)")
+ self.cursor.execute("create table debuginfo (debug_id integer primary key
autoincrement, rpm text)")
+ self.cursor.execute("create table timestamp (timestamp_id integer primary
key autoincrement, debugpath text, timestamp text, debug_id integer)")
+ self.commit()
+ return
+
# DEBUGINFO METHODS
def addDebuginfoRPM(self, debuginfo):
- self.cursor.execute("INSERT into debuginfo('rpm') values(?)",
debuginfo)
+ self.cursor.execute("SELECT * from debuginfo where debuginfo=?",
debuginfo)
+ if not self.cursor.fetchone():
+ self.cursor.execute("INSERT into debuginfo('rpm')
values(?)", debuginfo)
+ self.commit()
return
- def getDebuginfoRPM(self):
+ def getAllDebuginfoRPM(self):
self.cursor.execute("SELECT * FROM debuginfo")
- return self.cursor
+ return self.cursor.fetchall()
# TIMESTAMP METHODS
def addTimestamp(self, id, debug, timestamp):
""" build relation to debuginfo rpm and add debug path, timestamp
"""
- self.cursor.execute("""INSERT into
timestamp('debug_id','debugpath',
+ self.cursor.execute("""INSERT into timestamp
('debug_id','debugpath',
'timestamp') values(?,?,?)""", id, debug, timestamp)
-
- def connect(self):
- """ execute connection """
- try:
- 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')
+ self.commit()
return
+ # JOB METHODS
def getAllJobs(self):
""" all jobs """
self.cursor.execute("SELECT * FROM cas_jobs")
- return self.cursor
+ return self.cursor.fetchall()
def getJobById(self, id):
""" single job """
self.cursor.execute("SELECT * FROM cas_jobs where id=?", id)
- return self.cursor
+ return self.cursor.fetchone()
def getJobRange(self, days):
""" provides jobs based on creation date from
$days back
"""
pass
+
+ def addJob(self, submitter, corepath, debug_id, server_id):
+ """ add job to db """
+ self.cursor.execute("""INSERT into cas_jobs
('date','submitter',
+ 'corepath', debug_id, server_id, iterations)
+ values (?,?,?,?,?,?)""", date, submitter, corepath, debug_id,
server_id, 0)
+ return