]> git.decadent.org.uk Git - dak.git/commitdiff
Improve db conf handling
authorMark Hymers <mhy@debian.org>
Tue, 22 Mar 2011 10:41:17 +0000 (10:41 +0000)
committerMark Hymers <mhy@debian.org>
Tue, 22 Mar 2011 10:41:17 +0000 (10:41 +0000)
Signed-off-by: Mark Hymers <mhy@debian.org>
dak/admin.py
daklib/dbconn.py

index c7d770bae71ac7f8f4231f400236e3a4e6bd0dc4..663b196b64db06534df436c910ed40d519575362 100755 (executable)
@@ -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)
index 4c6f38340676670e27b41373e7780aa81b5ce1cf..979256e0c5c0969c24d94fd1c60df57f40baabfb 100755 (executable)
@@ -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 }