From 88d4f61e4df7dcffaaed083989c75ee9ad4a48a4 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 25 May 2023 19:19:22 +0300 Subject: Add some error checks. --- scripts/migrate_existing_data.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/migrate_existing_data.py b/scripts/migrate_existing_data.py index ecad39c..5c7e568 100644 --- a/scripts/migrate_existing_data.py +++ b/scripts/migrate_existing_data.py @@ -4,6 +4,7 @@ group for accessibility purposes. """ import sys import json +from pathlib import Path from uuid import UUID, uuid4 import click @@ -336,12 +337,17 @@ def assign_data_to_resource(authconn, bioconn, resource: Resource): authconn, bioconn, resource) @click.command() -@click.argument("authdburi") # "URI to the Auth(entic|oris)ation database" +@click.argument("authdbpath") # "Path to the Auth(entic|oris)ation database" @click.argument("mysqldburi") # "URI to the MySQL database with the biology data" -def run(authdburi, mysqldburi): +def run(authdbpath, mysqldburi): """Entry-point for data migration.""" + if not Path(authdbpath).exists(): + print( + f"ERROR: Auth db file `{authdbpath}` does not exist.", + file=sys.stderr) + sys.exit(2) try: - with (authdb.connection(authdburi) as authconn, + with (authdb.connection(authdbpath) as authconn, biodb.database_connection(mysqldburi) as bioconn): admin = select_sys_admin(sys_admins(authconn)) resources = default_resources( -- cgit v1.2.3