Make all postgres connection parameters optional

This commit is contained in:
Davlet Panech 2010-09-20 17:09:55 -04:00
parent b323952e63
commit 441ce481a1
2 changed files with 17 additions and 11 deletions

View File

@ -51,16 +51,13 @@ elif PSYCOPG_VERSION == 2:
class db:
""" a db connexion and utility class """
def __init__(self,
host, port, base, user, passwd,
dsn,
client_encoding = PG_CLIENT_ENCODING,
copy_every = 10000, commit_every = 1000, connect = True):
""" Connects to the specified database """
self.log = log
self.dbconn = None
self.dsn = "host=%s port=%d user=%s dbname=%s password=%s" \
% (host, port, user, base, passwd)
self.connect = "-h %s -p %s -U %s" % (host, port, user)
self.base = base
self.dsn = dsn
# those parameters can be overwritten after db init
# here's their default values

View File

@ -157,12 +157,21 @@ class PGLoader(threading.Thread):
return
try:
self.db = db(config.get(section, 'host'),
config.getint(section, 'port'),
config.get(section, 'base'),
config.get(section, 'user'),
config.get(section, 'pass'),
connect = False)
dsn = [];
if config.has_option(section, 'host'):
dsn.append ("host=%s" % config.get(section, 'host'))
if config.has_option(section, 'port'):
dsn.append ("port=%d" % config.getint(section, 'port'))
if config.has_option(section, 'base'):
dsn.append ("dbname=%s" % config.get(section, 'base'))
if config.has_option(section, 'user'):
dsn.append ("user=%s" % config.get(section, 'user'))
if config.has_option(section, 'pass'):
dsn.append ("password=%s" % config.get(section, 'pass'))
if config.has_option(section, 'sslmode'):
dsn.append ("sslmode=%s" % config.get(section, 'sslmode'))
self.db = db(" ".join (dsn), connect = False)
for opt in ['client_encoding', 'datestyle', 'lc_messages']:
if config.has_option(section, opt):