]> err.no Git - dak/commitdiff
Give slightly nicer error message on db conn failure
authorMark Hymers <mhy@debian.org>
Sat, 30 Jul 2011 21:26:52 +0000 (22:26 +0100)
committerMark Hymers <mhy@debian.org>
Sat, 30 Jul 2011 21:26:52 +0000 (22:26 +0100)
Signed-off-by: Mark Hymers <mhy@debian.org>
daklib/dbconn.py

index 6d954c88884095e1aba61338917d912ddc133660..7e9ff53931185fe8ce499654d4559bae3180e05c 100755 (executable)
@@ -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):