summaryrefslogtreecommitdiff
path: root/tko/db.py
diff options
context:
space:
mode:
authormbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2008-01-10 16:38:30 +0000
committermbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4>2008-01-10 16:38:30 +0000
commita0553c3837f4c471e7ade82509c3993a1c353146 (patch)
tree00423cb0243ef691a9351e5e0c0f5974fcc43bad /tko/db.py
parent398fcbd38638ba9366ab97e24606d45d67a7507b (diff)
Allow caller to override database params in db.py
Signed-off-by: Martin Bligh <mbligh@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@1142 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko/db.py')
-rw-r--r--tko/db.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/tko/db.py b/tko/db.py
index 1cce50f8..605587af 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -1,7 +1,8 @@
import re, os, sys, types
class db_sql:
- def __init__(self, debug = False, autocommit=True):
+ def __init__(self, debug = False, autocommit=True, host = None,
+ database = None, user = None, password = None):
self.debug = debug
self.autocommit = autocommit
@@ -9,26 +10,36 @@ class db_sql:
try:
file = os.path.join(path, '.database')
db_prefs = open(file, 'r')
- host = db_prefs.readline().rstrip()
- database = db_prefs.readline().rstrip()
+ if not host:
+ host = db_prefs.readline().rstrip()
+ if not database:
+ database = db_prefs.readline().rstrip()
except:
- host = 'localhost'
- database = 'tko'
+ if not host:
+ host = 'localhost'
+ if not database:
+ database = 'tko'
try:
file = os.path.join(path, '.priv_login')
login = open(file, 'r')
- user = login.readline().rstrip()
- password = login.readline().rstrip()
+ if not user:
+ user = login.readline().rstrip()
+ if not password:
+ password = login.readline().rstrip()
except:
try:
file = os.path.join(path, '.unpriv_login')
login = open(file, 'r')
- user = login.readline().rstrip()
- password = login.readline().rstrip()
+ if not user:
+ user = login.readline().rstrip()
+ if not password:
+ password = login.readline().rstrip()
except:
- user = 'nobody'
- password = ''
+ if not user:
+ user = 'nobody'
+ if not password:
+ password = ''
self.con = self.connect(host, database, user, password)
self.cur = self.con.cursor()