mirror of
https://github.com/dimitri/pgloader.git
synced 2026-05-05 02:46:10 +02:00
Merge remote branch 'refs/remotes/dpanech/dsn'
This commit is contained in:
commit
f97c09cc3b
@ -52,16 +52,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
|
||||
|
||||
@ -158,12 +158,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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user