Skip to content

Commit

Permalink
Merge pull request #320 from widdowquinn/issue_289
Browse files Browse the repository at this point in the history
Issue #289: Check for the existence of a database file that is passed
  • Loading branch information
baileythegreen committed Apr 13, 2022
2 parents 55a1492 + 8c80148 commit a4bc1b2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pyani/scripts/pyani_script.py
Expand Up @@ -42,6 +42,7 @@
import logging
import sys
import time
import os

from typing import List, Optional

Expand All @@ -59,7 +60,8 @@
"If you use pyani in your work, please cite the following publication:", "green"
),
termcolor(
"\tPritchard, L., Glover, R. H., Humphris, S., Elphinstone, J. G.,", "yellow"
"\tPritchard, L., Glover, R. H., Humphris, S., Elphinstone, J. G.,",
"yellow",
),
termcolor(
"\t& Toth, I.K. (2016) 'Genomics and taxonomy in diagnostics for", "yellow"
Expand Down Expand Up @@ -122,6 +124,20 @@ def run_main(argv: Optional[List[str]] = None) -> int:
logger.info("command-line: %s", args.cmdline)
add_log_headers()

# Check the database file exists, if one is given
# `dbpath` is not in the namespace for all subcommands,
# such as `download`, so a `try/except` is needed here
try:
if args.dbpath:
logger.info("Checking for database file: {args.dbpath}")
if not os.path.isfile(args.dbpath):
logger.error(
f"No database file at {args.dbpath}. Create one using `pyani createdb`."
)
return 0
except AttributeError:
pass

# Run the subcommand
returnval = args.func(args)
logger.info(
Expand Down

2 comments on commit a4bc1b2

@robert102
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) the check for the db file also triggers when running 'pyani createdb', making that subcommand non-functional
(2) line 132: f for f-string missing

@widdowquinn
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling in #389

Please sign in to comment.