changeset 328:ae37289007c3

fixed database config : None values can't be used anymore
author Goffi <goffi@goffi.org>
date Fri, 03 Mar 2017 08:35:34 +0100
parents 6662cc9519cc
children 98409ef42c94
files sat_pubsub/tap.py
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/tap.py	Wed Mar 09 10:41:38 2016 +0100
+++ b/sat_pubsub/tap.py	Fri Mar 03 08:35:34 2017 +0100
@@ -108,15 +108,24 @@
         from twisted.enterprise import adbapi
         from sat_pubsub.pgsql_storage import Storage
         from psycopg2.extras import NamedTupleConnection
+        keys_map = {
+            'dbuser': 'user',
+            'dbpass': 'password',
+            'dbname': 'database',
+            'dbhost': 'host',
+            'dbport': 'port',
+        }
+        kwargs = {}
+        for config_k, k in keys_map.iteritems():
+            v = config.get(config_k)
+            if v is None:
+                continue
+            kwargs[k] = v
         dbpool = adbapi.ConnectionPool('psycopg2',
-                                       user=config['dbuser'],
-                                       password=config['dbpass'],
-                                       database=config['dbname'],
-                                       host=config['dbhost'],
-                                       port=config['dbport'],
                                        cp_reconnect=True,
                                        client_encoding='utf-8',
                                        connection_factory=NamedTupleConnection,
+                                       **kwargs
                                        )
         st = Storage(dbpool)
     elif config['backend'] == 'memory':