From 070d7487fe4574bb04d21ab752383f179b7c1f79 Mon Sep 17 00:00:00 2001 From: gbouras13 Date: Fri, 8 Mar 2024 11:57:05 +1030 Subject: [PATCH] Fix #49 ensure --force works 2 --- src/plassembler/__init__.py | 6 +++--- src/plassembler/utils/db.py | 25 +++++++++++++------------ tests/test_db.py | 6 +++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/plassembler/__init__.py b/src/plassembler/__init__.py index 9606994..9c45803 100644 --- a/src/plassembler/__init__.py +++ b/src/plassembler/__init__.py @@ -434,7 +434,7 @@ def run( # check the mash database is installed logger.info("Checking database installation.") - check_db_installation(Path(database), install_flag=False) + check_db_installation(Path(database), force=False, install_flag=False) # will only continue if successful logger.info("Database successfully checked.") @@ -996,7 +996,7 @@ def assembled( # check the mash database is installed logger.info("Checking database installation.") - check_db_installation(Path(database), install_flag=False) + check_db_installation(Path(database), force=False, install_flag=False) # will only continue if successful logger.info("Database successfully checked.") @@ -1319,7 +1319,7 @@ def long( # check the mash database is installed logger.info("Checking database installation.") - check_db_installation(Path(database), install_flag=False) + check_db_installation(Path(database), force=False, install_flag=False) # will only continue if successful logger.info("Database successfully checked.") diff --git a/src/plassembler/utils/db.py b/src/plassembler/utils/db.py index 724f447..75dc14d 100755 --- a/src/plassembler/utils/db.py +++ b/src/plassembler/utils/db.py @@ -29,19 +29,20 @@ def check_db_installation(db_dir: Path, force: bool, install_flag: bool): f1: Path = db_dir / f"{mash_db_names[0]}" f2: Path = db_dir / f"{mash_db_names[1]}" - if force is True: - if os.path.isdir(db_dir) is True: - logger.info(f"Removing the directory {db_dir} as --force was specified") - shutil.rmtree(db_dir) + if install_flag is True: + if force is True: + if os.path.isdir(db_dir) is True: + logger.info(f"Removing the directory {db_dir} as --force was specified") + shutil.rmtree(db_dir) + else: + logger.info( + f"--force was specified even though the directory {db_dir} does not already exist. Continuing" + ) else: - logger.info( - f"--force was specified even though the directory {db_dir} does not already exist. Continuing" - ) - else: - if os.path.isdir(db_dir) is True: - logger.error( - f"Directory {db_dir} already exists and force was not specified. Please specify -f or --force to overwrite {db_dir}" - ) + if os.path.isdir(db_dir) is True: + logger.error( + f"Directory {db_dir} already exists and force was not specified. Please specify -f or --force to overwrite {db_dir}" + ) # instantiate outdir if os.path.isdir(db_dir) is False: diff --git a/tests/test_db.py b/tests/test_db.py index 4d53db7..45c98d4 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -40,15 +40,15 @@ class test_install(unittest.TestCase): # for plassembler run def test_check_db_installation_good(self): - check_db_installation(db_path, False) + check_db_installation(db_path, force=False, install_flag=False) # for plassembler download def test_check_db_installation_good_d(self): - check_db_installation(db_path, True) + check_db_installation(db_path, force=True, install_flag=True) def test_check_db_installation_bad(self): with self.assertRaises(SystemExit): - check_db_installation(val_data, False) + check_db_installation(val_data, force=False, install_flag=False) def test_get_database_zenodo(self): expected_return = True