Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eodag/api/product/_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(
self.provider = provider
self.product_type = kwargs.get("productType")
self.location = self.remote_location = properties.get("downloadLink", "")
self.assets = AssetsDict(self)
self.assets = AssetsDict(self, properties.pop("assets"))
self.properties = {
key: value
for key, value in properties.items()
Expand Down
49 changes: 26 additions & 23 deletions eodag/plugins/download/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,29 +577,34 @@ def download(
product.location = path_to_uri(fs_path)
return fs_path

# download assets if exist instead of remote_location
if len(product.assets) > 0 and (
not getattr(self.config, "ignore_assets", False)
or kwargs.get("asset", None) is not None
):
try:
assets_values = product.assets.get_values(kwargs.get("asset", None))
except NotAvailableError as e:
if kwargs.get("asset", None) is not None:
raise NotAvailableError(e).with_traceback(e.__traceback__)

# download single assets if there is no the full product asset
if all([assets_val.key != "downloadLink" for assets_val in assets_values]):
try:
fs_path = self._download_assets(
product,
fs_path.replace(".zip", ""),
fs_path.replace(kwargs["outputs_extension"], ""),
record_filename,
auth,
progress_callback,
**kwargs,
)
if kwargs.get("asset", None) is None:
product.location = path_to_uri(fs_path)
return fs_path
except NotAvailableError as e:
if kwargs.get("asset", None) is not None:
raise NotAvailableError(e).with_traceback(e.__traceback__)
else:
pass

# download the full product asset
if len(assets_values) > 1 and kwargs.get("asset", None) is not None:
logger.info("Download only the full product asset, ignoring the other ones")

url = product.remote_location

@self._download_retry(product, wait, timeout)
Expand All @@ -611,7 +616,9 @@ def download_request(
timeout: int,
**kwargs: Unpack[DownloadConf],
) -> None:
chunks = self._stream_download(product, auth, progress_callback, **kwargs)
chunks = self._stream_download_full_product_asset(
product, auth, progress_callback, **kwargs
)
is_empty = True

with open(fs_path, "wb") as fhandle:
Expand Down Expand Up @@ -809,7 +816,9 @@ def _stream_download_dict(
else:
pass

chunks = self._stream_download(product, auth, progress_callback, **kwargs)
chunks = self._stream_download_full_product_asset(
product, auth, progress_callback, **kwargs
)
# start reading chunks to set product.headers
try:
first_chunk = next(chunks)
Expand Down Expand Up @@ -880,16 +889,17 @@ def _process_exception(
else:
logger.error("Error while getting resource :\n%s", tb.format_exc())

def _stream_download(
def _stream_download_full_product_asset(
self,
product: EOProduct,
auth: Optional[AuthBase] = None,
progress_callback: Optional[ProgressCallback] = None,
**kwargs: Unpack[DownloadConf],
) -> Iterator[Any]:
"""
fetches a zip file containing the assets of a given product as a stream
and returns a generator yielding the chunks of the file
fetches the zip file of the full product asset containing the assets
of a given product as a stream and returns a generator yielding the
chunks of the file
:param product: product for which the assets should be downloaded
:param auth: The configuration of a plugin of type Authentication
:param progress_callback: A method or a callable object
Expand Down Expand Up @@ -1009,13 +1019,6 @@ def _stream_download_assets(
logger.info("Progress bar unavailable, please call product.download()")
progress_callback = ProgressCallback(disable=True)

assets_urls = [
a["href"] for a in getattr(product, "assets", {}).values() if "href" in a
]

if not assets_urls:
raise NotAvailableError("No assets available for %s" % product)

# get extra parameters to pass to the query
params = kwargs.pop("dl_url_params", None) or getattr(
self.config, "dl_url_params", {}
Expand Down Expand Up @@ -1140,10 +1143,10 @@ def _download_assets(
progress_callback = ProgressCallback(disable=True)

assets_urls = [
a["href"] for a in getattr(product, "assets", {}).values() if "href" in a
a["href"]
for a in getattr(product, "assets", {}).values()
if "href" in a and a.key != "downloadLink"
]
if not assets_urls:
raise NotAvailableError("No assets available for %s" % product)

assets_values = product.assets.get_values(kwargs.get("asset", None))

Expand Down
2 changes: 0 additions & 2 deletions eodag/plugins/search/qssearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,6 @@ def normalize_results(
product.properties = dict(
getattr(self.config, "product_type_config", {}), **product.properties
)
# move assets from properties to product's attr
product.assets.update(product.properties.pop("assets", {}))
products.append(product)
return products

Expand Down
1 change: 0 additions & 1 deletion eodag/resources/providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7427,7 +7427,6 @@
download: !plugin
type: HTTPDownload
extract: true
ignore_assets: True
ssl_verify: true
auth: !plugin
type: TokenAuth
Expand Down