-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include receipts in downloads and refactor of common code (#67)
* make_receipt method added * Refactor * default receipt=False * defaults from CDS * warning for bad format requested, allow format conversion kwargs
- Loading branch information
Showing
5 changed files
with
198 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,26 @@ | ||
from typing import BinaryIO | ||
|
||
from cads_adaptors import mapping | ||
from cads_adaptors.adaptors import Request, cds | ||
|
||
|
||
class UrlCdsAdaptor(cds.AbstractCdsAdaptor): | ||
def retrieve(self, request: Request) -> BinaryIO: | ||
from cads_adaptors.tools import download_tools, url_tools | ||
# TODO: Remove legacy syntax all together | ||
if "format" in request: | ||
_download_format = request.pop("format") | ||
request.setdefault("download_format", _download_format) | ||
|
||
download_format = request.pop("format", "zip") # TODO: Remove legacy syntax | ||
# CADS syntax over-rules legacy syntax | ||
download_format = request.pop("download_format", download_format) | ||
self._pre_retrieve(request=request) | ||
|
||
# Do not need to check twice | ||
# if download_format not in {"zip", "tgz"}: | ||
# raise ValueError(f"{download_format} is not supported") | ||
|
||
mapped_request = mapping.apply_mapping(request, self.mapping) # type: ignore | ||
from cads_adaptors.tools import url_tools | ||
|
||
# Convert request to list of URLs | ||
requests_urls = url_tools.requests_to_urls( | ||
mapped_request, patterns=self.config["patterns"] | ||
self.mapped_request, patterns=self.config["patterns"] | ||
) | ||
|
||
# try to download URLs | ||
urls = [ru["url"] for ru in requests_urls] | ||
paths = url_tools.try_download(urls) | ||
|
||
download_kwargs = {"base_target": f"{self.collection_id}-{hash(tuple(urls))}"} | ||
|
||
return download_tools.DOWNLOAD_FORMATS[download_format]( | ||
paths, **download_kwargs | ||
) | ||
return self.make_download_object(paths) |
Oops, something went wrong.