From e5bc0b3dccd5874054ad585157cbe2b05758b654 Mon Sep 17 00:00:00 2001 From: Mark Hymers Date: Sat, 30 Jul 2011 22:26:52 +0100 Subject: [PATCH] Give slightly nicer error message on db conn failure Signed-off-by: Mark Hymers --- daklib/dbconn.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 6d954c88..7e9ff539 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -3664,15 +3664,21 @@ class DBConn(object): 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 - self.db_smaker = sessionmaker(bind=self.db_pg, - autoflush=True, - autocommit=False) - - self.__setuptables() - self.__setupmappers() + try: + self.db_pg = create_engine(connstr, **engine_args) + self.db_meta = MetaData() + self.db_meta.bind = self.db_pg + self.db_smaker = sessionmaker(bind=self.db_pg, + autoflush=True, + autocommit=False) + + self.__setuptables() + self.__setupmappers() + + except OperationalError, e: + import utils + utils.fubar("Cannot connect to database (%s)" % str(e)) + self.pid = os.getpid() def session(self, work_mem = 0): -- 2.39.5