PgDB: fix connect() return and improve logging

This commit is contained in:
Benjamin Renard 2021-07-12 12:11:38 +02:00
parent 64c2db5d5d
commit 198d6021b4

25
PgDB.py
View file

@ -25,14 +25,23 @@ class PgDB(object):
self.pwd = pwd self.pwd = pwd
self.db = db self.db = db
def connect(self): def connect(self):
if self.con == 0: if self.con == 0:
try: try:
con = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (self.db,self.user,self.host,self.pwd)) con = psycopg2.connect(
self.con = con dbname=self.db,
except Exception: user=self.user,
logging.fatal('An error occured during Postgresql database connection.', exc_info=1) host=self.host,
sys.exit(1) password=self.pwd
)
self.con = con
except Exception:
logging.fatal(
'An error occured during Postgresql database connection (%s@%s, database=%s).',
self.user, self.host, self.db, exc_info=1
)
sys.exit(1)
return True
def close(self): def close(self):
if self.con: if self.con: