From: Mark Hymers Date: Tue, 22 Mar 2011 10:18:57 +0000 (+0000) Subject: Patch in support for service= DSN syntax X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35eea3b7e76b202f70ef627db6547d334e8c91ed;p=dak Patch in support for service= DSN syntax Signed-off-by: Mark Hymers --- diff --git a/config/debian/dak.conf b/config/debian/dak.conf index 97aaa01d..a9eb3fb4 100644 --- a/config/debian/dak.conf +++ b/config/debian/dak.conf @@ -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 diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 6cd84de3..4c6f3834 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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