12
12
from tqdm import tqdm
13
13
14
14
from cads_adaptors .adaptors import Context
15
+ from cads_adaptors .exceptions import InvalidRequest , UrlNoDataError
15
16
from cads_adaptors .tools import hcube_tools
16
17
17
18
@@ -66,17 +67,18 @@ def try_download(urls: List[str], context: Context, **kwargs) -> List[str]:
66
67
if len (paths ) == 0 :
67
68
context .add_user_visible_error (
68
69
"Your request has not found any data, please check your selection.\n "
69
- "If you believe this to be a data store error, please contact user support."
70
+ "This may be due to temporary connectivity issues with the source data.\n "
71
+ "If this problem persists, please contact user support."
70
72
)
71
- raise RuntimeError (
73
+ raise UrlNoDataError (
72
74
f"Request empty. No data found from the following URLs:"
73
75
f"\n { yaml .safe_dump (urls , indent = 2 )} "
74
76
)
75
77
# TODO: raise a warning if len(paths)<len(urls). Need to check who sees this warning
76
78
return paths
77
79
78
80
79
- # TODO use targzstream
81
+ # TODO: remove unused function
80
82
def download_zip_from_urls (
81
83
urls : List [str ],
82
84
base_target : str ,
@@ -94,7 +96,7 @@ def download_zip_from_urls(
94
96
return target
95
97
96
98
97
- # TODO zipstream for archive creation
99
+ # TODO: remove unused function
98
100
def download_tgz_from_urls (
99
101
urls : List [str ],
100
102
base_target : str ,
@@ -112,27 +114,29 @@ def download_tgz_from_urls(
112
114
return target
113
115
114
116
117
+ # TODO: remove unused function
115
118
def download_from_urls (
116
119
urls : List [str ],
117
120
context : Context ,
118
- data_format : str = "zip" ,
121
+ download_format : str = "zip" ,
119
122
) -> str :
120
123
base_target = str (hash (tuple (urls )))
121
124
122
- if data_format == "tgz" :
125
+ if download_format == "tgz" :
123
126
target = download_tgz_from_urls (
124
127
urls = urls , base_target = base_target , context = context
125
128
)
126
- elif data_format == "zip" :
129
+ elif download_format == "zip" :
127
130
target = download_zip_from_urls (
128
131
urls = urls , base_target = base_target , context = context
129
132
)
130
133
else :
131
- raise ValueError (f"{ data_format = } is not supported" )
134
+ raise InvalidRequest (f"Download format ' { download_format } ' is not supported" )
132
135
133
136
return target
134
137
135
138
139
+ # TODO: remove unused function
136
140
def download_zip_from_urls_in_memory (
137
141
urls : List [str ], target : Optional [str ] = None
138
142
) -> str :
0 commit comments