Skip to content

Commit

Permalink
Fix #49 ensure --force works 2
Browse files Browse the repository at this point in the history
  • Loading branch information
gbouras13 committed Mar 8, 2024
1 parent 8d99360 commit 070d748
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/plassembler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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.")

Expand Down
25 changes: 13 additions & 12 deletions src/plassembler/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 070d748

Please sign in to comment.