From b8d1a705c16f087e93d2ee8232c1ecf379242e86 Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Tue, 22 Mar 2011 10:41:17 +0000 Subject: [PATCH] Improve db conf handling Signed-off-by: Mark Hymers --- dak/admin.py | 19 +++++++++++++------ daklib/dbconn.py | 8 ++++---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/dak/admin.py b/dak/admin.py index c7d770ba..663b196b 100755 --- a/dak/admin.py +++ b/dak/admin.py @@ -343,10 +343,13 @@ def show_config(command): if mode == 'db': connstr = "" - if cnf["DB::Host"]: + if cnf.has_key("DB::Service"): + # Service mode + connstr = "postgresql://service=%s" % cnf["DB::Service"] + elif cnf.has_key("DB::Host"): # TCP/IP connstr = "postgres://%s" % cnf["DB::Host"] - if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + if cnf.has_key("DB::Port") and cnf["DB::Port"] != "-1": connstr += ":%s" % cnf["DB::Port"] connstr += "/%s" % cnf["DB::Name"] else: @@ -356,12 +359,16 @@ def show_config(command): connstr += "?port=%s" % cnf["DB::Port"] print connstr elif mode == 'db-shell': - e = ['PGDATABASE'] - print "PGDATABASE=%s" % cnf["DB::Name"] - if cnf["DB::Host"]: + if cnf.has_key("DB::Service"): + e.append('PGSERVICE') + print "PGSERVICE=%s" % cnf["DB::Service"] + if cnf.has_key("DB::Name"): + e.append('PGDATABASE') + print "PGDATABASE=%s" % cnf["DB::Name"] + if cnf.has_key("DB::Host"): print "PGHOST=%s" % cnf["DB::Host"] e.append('PGHOST') - if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + if cnf.has_key("DB::Port") and cnf["DB::Port"] != "-1": print "PGPORT=%s" % cnf["DB::Port"] e.append('PGPORT') print "export " + " ".join(e) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 4c6f3834..979256e0 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -3164,18 +3164,18 @@ class DBConn(object): def __createconn(self): from config import Config cnf = Config() - if cnf["DB::Service"]: + if cnf.has_key("DB::Service"): connstr = "postgresql://service=%s" % cnf["DB::Service"] - elif cnf["DB::Host"]: + elif cnf.has_key("DB::Host"): # TCP/IP connstr = "postgresql://%s" % cnf["DB::Host"] - if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + if cnf.has_key("DB::Port") and cnf["DB::Port"] != "-1": connstr += ":%s" % cnf["DB::Port"] connstr += "/%s" % cnf["DB::Name"] else: # Unix Socket connstr = "postgresql:///%s" % cnf["DB::Name"] - if cnf["DB::Port"] and cnf["DB::Port"] != "-1": + if cnf.has_key("DB::Port") and cnf["DB::Port"] != "-1": connstr += "?port=%s" % cnf["DB::Port"] engine_args = { 'echo': self.debug } -- 2.39.2