summaryrefslogtreecommitdiff
path: root/framework/database.py
diff options
context:
space:
mode:
Diffstat (limited to 'framework/database.py')
-rw-r--r--framework/database.py56
1 files changed, 31 insertions, 25 deletions
diff --git a/framework/database.py b/framework/database.py
index 9ab2983..b441ad5 100644
--- a/framework/database.py
+++ b/framework/database.py
@@ -22,33 +22,39 @@
#
import apsw
import sys
+import time
import os.path as path
import xdg.BaseDirectory as xdg
-__all__ = ['load']
+__all__ = ['ResultDatabase']
-def load(config):
- '''Load the results database, creating it if it doesn't exist.
-
- Will exit the program if it fails.'''
- try:
- connection = apsw.Connection(config['options']['database'])
- cursor = connection.cursor()
+class ResultDatabase:
+ def __init__(self, config):
+ '''Load the results database, creating it if it doesn't exist.
- cursor.execute('''CREATE TABLE IF NOT EXISTS runs
- (date INTEGER,
- name TEXT,
- driver TEXT,
- sysinfo TEXT)''')
- cursor.execute('''CREATE TABLE IF NOT EXISTS results
- (run_id INTEGER,
- test_name TEXT,
- command TEXT,
- result TEXT,
- return_code INTEGER,
- errors TEXT,
- output TEXT)''')
- return cursor
- except OSError as e:
- print('error: could not open results database', str(e), '\n')
- sys.exit(0)
+ Will exit the program if it fails.'''
+ try:
+ self.connection = apsw.Connection(config['options']['database'])
+ cursor = self.connection.cursor()
+
+ cursor.execute('''CREATE TABLE IF NOT EXISTS runs
+ (date INTEGER PRIMARY KEY,
+ name TEXT,
+ driver TEXT,
+ sysinfo TEXT)''')
+ cursor.execute('''CREATE TABLE IF NOT EXISTS results
+ (run_id INTEGER,
+ test_name TEXT,
+ command TEXT,
+ result TEXT,
+ return_code INTEGER,
+ errors TEXT,
+ output TEXT)''')
+ except OSError as e:
+ print('error: could not open results database', str(e), '\n')
+ sys.exit(0)
+
+ def createRun(self, name, driver, sysinfo):
+ cursor = self.connection.cursor()
+ date = int(time.time())
+ cursor.execute('INSERT INTO runs values(?,?,?,?)', (date, name, driver, sysinfo))