]> err.no Git - dak/commitdiff
Patch in support for service= DSN syntax
authorMark Hymers <mhy@debian.org>
Tue, 22 Mar 2011 10:18:57 +0000 (10:18 +0000)
committerMark Hymers <mhy@debian.org>
Tue, 22 Mar 2011 10:18:57 +0000 (10:18 +0000)
Signed-off-by: Mark Hymers <mhy@debian.org>
config/debian/dak.conf
daklib/dbconn.py

index 97aaa01db26d46c381fe25a0a0237d65d715689e..a9eb3fb4271e64f943e23509980b7307bc9b3270 100644 (file)
@@ -451,9 +451,7 @@ Queue-Report
 
 DB
 {
-  Name "projectb";
-  Host "";
-  Port 5433;
+  Service "projectb";
   // PoolSize should be at least ThreadCount + 1
   PoolSize 17;
   // MaxOverflow shouldn't exceed postgresql.conf's max_connections - PoolSize
index 6cd84de3f30da9fe9c93167c9954b17929dbc8d1..4c6f38340676670e27b41373e7780aa81b5ce1cf 100755 (executable)
@@ -3164,15 +3164,17 @@ class DBConn(object):
     def __createconn(self):
         from config import Config
         cnf = Config()
-        if cnf["DB::Host"]:
+        if cnf["DB::Service"]:
+            connstr = "postgresql://service=%s" % cnf["DB::Service"]
+        elif cnf["DB::Host"]:
             # TCP/IP
-            connstr = "postgres://%s" % cnf["DB::Host"]
+            connstr = "postgresql://%s" % cnf["DB::Host"]
             if cnf["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"]
+            connstr = "postgresql:///%s" % cnf["DB::Name"]
             if cnf["DB::Port"] and cnf["DB::Port"] != "-1":
                 connstr += "?port=%s" % cnf["DB::Port"]
 
@@ -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