Add very basic database stuff



git-svn-id: http://test.kernel.org/svn/autotest/trunk@313 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/create_db b/tko/create_db
new file mode 100644
index 0000000..cd5d74f
--- /dev/null
+++ b/tko/create_db
@@ -0,0 +1,28 @@
+BEGIN TRANSACTION;
+
+CREATE TABLE versions (
+version  VARCHAR(100) PRIMARY KEY
+);
+
+CREATE TABLE jobs (
+job VARCHAR(15) PRIMARY KEY,
+version VARCHAR(100),
+status INTEGER,
+machine VARCHAR(20),
+kernel VARCHAR(30)
+);
+
+CREATE TABLE results (
+job VARCHAR(15),
+test VARCHAR(40) PRIMARY KEY,
+attribute VARCHAR(20),
+value INTEGER
+);
+
+CREATE TABLE patches (
+job VARCHAR(15) PRIMARY KEY,
+number INTEGER,
+patchname VARCHAR(100) 
+);
+
+COMMIT;
diff --git a/tko/db.py b/tko/db.py
new file mode 100644
index 0000000..d349ed4
--- /dev/null
+++ b/tko/db.py
@@ -0,0 +1,12 @@
+import sqlite
+
+class db:
+	def __init__(self):
+		self.con = sqlite.connect('tko_db')
+		self.cur = self.con.cursor()
+
+
+	def select(self, cmd):
+		self.cur.execute('select ' + cmd)
+		return self.cur.fetchall()
+
diff --git a/tko/parse b/tko/parse
index ab3649c..21ca728 100755
--- a/tko/parse
+++ b/tko/parse
@@ -10,7 +10,9 @@
 jobs_list = [j.strip() for j in jobs_list]
 
 for j in jobs_list:
-	key = 'abat' + j
-	job_dir = os.path.join(topdir, j)
-	jobs[key] = job.job(job_dir)
-	print key + ' ' + jobs[key].kernel
+	job = parse.parse(os.path.join(topdir, j), 'regression')
+	if not job.kernel:
+		continue
+	jobs['abat' + j] = job
+	# print '%s %s %s %s' % (j, job.kernel, job.status, job.reason)
+	print '%s %s' % (job.status, job.reason)
diff --git a/tko/parse.py b/tko/parse.py
index eeca5a0..8dea9f5 100755
--- a/tko/parse.py
+++ b/tko/parse.py
@@ -6,6 +6,23 @@
 build_url   = re.compile('build generic url \S*/linux-(2\.\d\.\d+(\.\d+)?(-rc\d+)?).tar')	
 valid_kernel= re.compile('2\.\d\.\d+(\.\d+)?(-rc\d+)?(-(git|bk))\d+')
 
+statuses = ['NOSTATUS', 'ERROR', 'ABORT', 'FAIL', 'WARN', 'GOOD']
+status_num = {}
+for x in range(0, len(statuses)):
+	status_num[statuses[x]] = x
+
+munge_reasons = (
+	(r', job abort.*', ''),
+	(r'autobench reported job failed, aborting', 'harness failed job'),
+	(r'machine did not return from reboot.*', 'reboot failed'),
+	(r'machine reboot failed', 'reboot failed'),
+	(r'machine reached login', 'reached login'),
+	(r'lost contact with run', 'lost contact'),
+	(r'\(machine panic.*', '(panic)'),
+	(r'.*build generic url.*', 'kernel build failed'),
+	(r'^.fs .*', 'fs operation failed'),
+		)
+
 
 def shorten_patch(long):
 	short = os.path.basename(long)
@@ -16,15 +33,22 @@
 	return short
 
 
+
+
 class parse:
-	def __init__(self, topdir):
+	def __init__(self, topdir, type):
 		self.topdir = topdir
-		self.control = "%s/autobench.dat" % topdir
+		self.type = type
+		self.control = os.path.join(topdir, "autobench.dat")
+		self.set_status('NOSTATUS')
+		self.reason = ''
 		self.variables = {}
 		self.kernel = None
 
-		if os.path.exists(self.control):
-			self.grope_datfile()
+		if not os.path.exists(self.control):
+			return
+		self.grope_datfile()
+		self.grope_status()
 
 
 	def grope_datfile(self):
@@ -79,4 +103,33 @@
 		match = valid_kernel.match(self.patches_short[0])
 		if match:
 			self.kernel = match.group()
-		
+
+
+	def grope_status(self):
+		status_file = os.path.join(self.topdir, "status")
+		try:
+			line = open(status_file, 'r').readline().rstrip()
+			(status, reason) = line.split(' ', 1)
+		except:
+			return
+
+		for (a, b) in munge_reasons:
+			reason = re.sub(a, b, reason)
+
+		if reason.count('run completed unexpectedly'):
+			try:
+				if os.system('head $resultsdir{$job}/debug/test.log.0 | grep "autobench already running, exiting" > /dev/null'):
+					status = 'FAIL'
+					reason = 'autobench already running'
+			except:
+				pass
+
+		self.set_status(status)
+		self.reason = reason
+
+
+	def set_status(self, status):
+		if status not in status_num:
+			return
+		self.status = status
+		self.status_num = status_num[status]
diff --git a/tko/retrieve b/tko/retrieve
new file mode 100755
index 0000000..74d8880
--- /dev/null
+++ b/tko/retrieve
@@ -0,0 +1,5 @@
+#!/usr/bin/python2.4
+import db
+
+db = db.db()
+print db.select('* from jobs')