1616from plassembler .utils .cleanup import remove_directory
1717
1818
19- def check_db_installation (db_dir : Path , install_flag : bool ):
19+ def check_db_installation (db_dir : Path , force : bool , install_flag : bool ):
2020 """checks database is installed correctly
2121 :param db_dir: database directory
22+ :param force: boolean if force is true
2223 :param install_flag: whether to check or install database
2324 """
2425 # Mash files
@@ -28,6 +29,25 @@ def check_db_installation(db_dir: Path, install_flag: bool):
2829 f1 : Path = db_dir / f"{ mash_db_names [0 ]} "
2930 f2 : Path = db_dir / f"{ mash_db_names [1 ]} "
3031
32+ if install_flag is True :
33+ if force is True :
34+ if os .path .isdir (db_dir ) is True :
35+ logger .info (f"Removing the directory { db_dir } as --force was specified" )
36+ shutil .rmtree (db_dir )
37+ else :
38+ logger .info (
39+ f"--force was specified even though the directory { db_dir } does not already exist. Continuing"
40+ )
41+ else :
42+ if os .path .isdir (db_dir ) is True :
43+ logger .error (
44+ f"Directory { db_dir } already exists and force was not specified. Please specify -f or --force to overwrite { db_dir } "
45+ )
46+
47+ # instantiate outdir
48+ if os .path .isdir (db_dir ) is False :
49+ os .mkdir (db_dir )
50+
3151 if f1 .exists () and f2 .exists ():
3252 logger .info (f"PLSDB Database mash sketch at { f1 } exists." )
3353 logger .info (f"PLSDB Database tsv metadata file at { f2 } exists." )
@@ -49,20 +69,12 @@ def check_db_installation(db_dir: Path, install_flag: bool):
4969
5070
5171def get_database_zenodo (db_dir : Path ):
52- logger .info ("Downloading Plassembler Database. " )
72+ logger .info (f "Downloading Plassembler Database to the directory { db_dir } " )
5373 tarball = "201123_plassembler_v1.5.0_databases.tar.gz"
5474 tar_path = Path (f"{ db_dir } /{ tarball } " )
5575 db_url = "https://zenodo.org/record/10158040/files/201123_plassembler_v1.5.0_databases.tar.gz"
5676 requiredmd5 = "3a24bacc05bb857dc044fc6662b58db7"
5777
58- # remvoe the directory
59- if os .path .exists (db_dir ):
60- shutil .rmtree (db_dir )
61-
62- # make db dir
63- if not os .path .exists (db_dir ):
64- os .mkdir (db_dir )
65-
6678 try :
6779 with tar_path .open ("wb" ) as fh_out , requests .get (db_url , stream = True ) as resp :
6880 total_length = resp .headers .get ("content-length" )
0 commit comments