11import argparse
2+ from os import PathLike
3+ from pathlib import Path
4+ from typing import Union
25import sys
36from .download .downloader import download as download_datasets
47
@@ -17,6 +20,21 @@ def main():
1720 'Alternatively "all" will download the full repository of '
1821 'coderdata datasets. See "coderdata --list" for a complete list '
1922 'of available datasets. Defaults to "all"'
23+ )
24+ parser_download .add_argument (
25+ '-p' , '--local_path' ,
26+ dest = "LOCAL_PATH" ,
27+ type = check_folder ,
28+ default = Path .cwd (),
29+ help = 'Defines the folder the datasets should be stored in. Defaults '
30+ 'to the current working directory if omitted.'
31+ )
32+ parser_download .add_argument (
33+ '-o' , '--overwrite' ,
34+ dest = "OVERWRITE" ,
35+ default = False ,
36+ action = 'store_true' ,
37+ help = 'Allow dataset files to be overwritten if they already exist.'
2038 )
2139 parser_download .set_defaults (func = download )
2240 if len (sys .argv ) == 1 :
@@ -26,7 +44,37 @@ def main():
2644 args .func (args )
2745
2846def download (args ):
29- download_datasets (name = args .DATASET_NAME )
47+ download_datasets (
48+ name = args .DATASET_NAME ,
49+ local_path = args .LOCAL_PATH ,
50+ exist_ok = args .OVERWRITE ,
51+ )
52+
53+
54+ def check_folder (path : Union [str , PathLike , Path ]) -> Path :
55+ """
56+ Helper function to check if a defined folder exists
57+ """
58+
59+ if not isinstance (path , (str , PathLike , Path )):
60+ raise TypeError (
61+ f"'path' must be of type str, PathLike or Path. Supplied argument "
62+ f"is of type { type (path )} ."
63+ )
64+ if not isinstance (path , Path ):
65+ abs_path = Path (path ).absolute ()
66+ else :
67+ abs_path = path .absolute ()
68+
69+ if not abs_path .is_dir ():
70+ raise OSError (
71+ f"The defined folder path '{ path } ' does not exist or is not a "
72+ f"folder."
73+ )
74+
75+ return abs_path
76+
77+
3078if __name__ == '__main__' :
3179 main ()
3280
0 commit comments