]> git.donarmstrong.com Git - dak.git/commitdiff
Merge branch 'master' of ssh://ftp-master.debian.org/srv/ftp.debian.org/git/dak
authorJoerg Jaspert <joerg@debian.org>
Tue, 22 Mar 2011 13:09:55 +0000 (14:09 +0100)
committerJoerg Jaspert <joerg@debian.org>
Tue, 22 Mar 2011 13:09:55 +0000 (14:09 +0100)
* 'master' of ssh://ftp-master.debian.org/srv/ftp.debian.org/git/dak:
  Fix typo
  Improve db conf handling
  Commit uncommitted fix
  Patch in support for service= DSN syntax

config/debian/dak.conf
dak/admin.py
daklib/dbconn.py

index 97aaa01db26d46c381fe25a0a0237d65d715689e..b888a6062eee558fb299894644109df97124030e 100644 (file)
@@ -451,11 +451,9 @@ Queue-Report
 
 DB
 {
-  Name "projectb";
-  Host "";
-  Port 5433;
+  Service "projectb";
   // PoolSize should be at least ThreadCount + 1
-  PoolSize 17;
+  PoolSize 5;
   // MaxOverflow shouldn't exceed postgresql.conf's max_connections - PoolSize
   MaxOverflow 13;
   // should be false for encoding == SQL_ASCII
index c7d770bae71ac7f8f4231f400236e3a4e6bd0dc4..218eea578ed7ef9bf5f78a32898f745570c91827 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,17 @@ 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"]:
+        e = []
+        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 6cd84de3f30da9fe9c93167c9954b17929dbc8d1..979256e0c5c0969c24d94fd1c60df57f40baabfb 100755 (executable)
@@ -3164,16 +3164,18 @@ class DBConn(object):
     def __createconn(self):
         from config import Config
         cnf = Config()
-        if cnf["DB::Host"]:
+        if cnf.has_key("DB::Service"):
+            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":
+            connstr = "postgresql://%s" % cnf["DB::Host"]
+            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 = "postgres:///%s" % cnf["DB::Name"]
-            if cnf["DB::Port"] and cnf["DB::Port"] != "-1":
+            connstr = "postgresql:///%s" % cnf["DB::Name"]
+            if cnf.has_key("DB::Port") and cnf["DB::Port"] != "-1":
                 connstr += "?port=%s" % cnf["DB::Port"]
 
         engine_args = { 'echo': self.debug }
@@ -3185,6 +3187,20 @@ class DBConn(object):
             cnf['DB::Unicode'] == 'false':
             engine_args['use_native_unicode'] = False
 
+        # Monkey patch a new dialect in in order to support service= syntax
+        import sqlalchemy.dialects.postgresql
+        from sqlalchemy.dialects.postgresql.psycopg2 import PGDialect_psycopg2
+        class PGDialect_psycopg2_dak(PGDialect_psycopg2):
+            def create_connect_args(self, url):
+                if str(url).startswith('postgresql://service='):
+                    # Eww
+                    servicename = str(url)[21:]
+                    return (['service=%s' % servicename], {})
+                else:
+                    return PGDialect_psycopg2.create_connect_args(self, url)
+
+        sqlalchemy.dialects.postgresql.base.dialect = PGDialect_psycopg2_dak
+
         self.db_pg   = create_engine(connstr, **engine_args)
         self.db_meta = MetaData()
         self.db_meta.bind = self.db_pg