diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-01-10 16:38:30 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-01-10 16:38:30 +0000 |
commit | a0553c3837f4c471e7ade82509c3993a1c353146 (patch) | |
tree | 00423cb0243ef691a9351e5e0c0f5974fcc43bad /tko/db.py | |
parent | 398fcbd38638ba9366ab97e24606d45d67a7507b (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.py | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -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() |