From 32f1504173923bf578786b0d6f586a04a4447310 Mon Sep 17 00:00:00 2001 From: Valerie R Young Date: Fri, 19 Aug 2016 15:13:52 -0400 Subject: reproducible debian: make sqlite3 locking errors less noisy Signed-off-by: Holger Levsen --- bin/reproducible_common.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/reproducible_common.py b/bin/reproducible_common.py index dcbe05e8..985f2eb7 100755 --- a/bin/reproducible_common.py +++ b/bin/reproducible_common.py @@ -30,6 +30,7 @@ from subprocess import call, check_call from tempfile import NamedTemporaryFile from datetime import datetime, timedelta from sqlalchemy import MetaData, Table, sql, create_engine +from sqlalchemy.exc import NoSuchTableError, OperationalError DEBUG = False QUIET = False @@ -365,7 +366,7 @@ def db_table(table_name): """ try: return Table(table_name, DB_METADATA, autoload=True) - except sqlalchemy.exc.NoSuchTableError: + except NoSuchTableError: log.error("Table %s does not exist or schema for %s could not be loaded", table_name, REPRODUCIBLE_DB) raise @@ -384,9 +385,16 @@ def query_db(query): """ try: result = conn_db.execute(query) - except: - print_critical_message('Error executing this query:\n' + query) - raise + except OperationalError as ex: + # if this sqlalchemy.exc.OperationalError was caused by a sqlite3 + # database locking error, the error will have the following format: + if ex.orig and ex.orig.args and ex.orig.args[0] == "database is locked": + print_critical_message('SQLite database locked, could not execute ' + + 'query:\n"%s"\nExiting script.' % query) + exit(1) + else: + print_critical_message('Error executing this query:\n' + query) + raise if result.returns_rows: return result.fetchall() -- cgit v1.2.3-70-g09d2