From 4675c79aebb9bcc2014cb26844ccca32172da144 Mon Sep 17 00:00:00 2001 From: Germano Guerrini Date: Fri, 2 Aug 2024 13:05:28 +0200 Subject: [PATCH 1/2] Separated download url computation --- hda/api.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/hda/api.py b/hda/api.py index 4835f4a..973c651 100644 --- a/hda/api.py +++ b/hda/api.py @@ -269,19 +269,38 @@ def __getitem__(self, index): def _download(self, result, download_dir: str = "."): logger.debug(result) self.client.accept_tac(self.dataset) + download_id = self._get_download_id(result) + self.stream( + download_id, + result["properties"]["size"], + download_dir, + ) + def _get_download_id(self, result): query = { "dataset_id": self.dataset, "product_id": result["id"], "location": result["properties"]["location"], } - download_id = DataOrderRequest(self.client).run(query) + return DataOrderRequest(self.client).run(query) - self.stream( - download_id, - result["properties"]["size"], - download_dir, - ) + def get_download_urls(self, limit: int = None): + """Utility function to return the list of final download URLs. + Useful in the context of the Serverless Functions service. + If the list of results is long, it might take a long time. + In that case, either subset the results or set a value for `limit`. + """ + + def build_url(result): + download_id = self._get_download_id(result) + return self.client.full_url(*[f"dataaccess/download/{download_id}"]) + + if limit is not None: + results = self.results[:limit] + else: + results = self.results + + return [build_url(r) for r in results] def download(self, download_dir: str = "."): """Downloads the results into the given download directory. From 774698e40f51d3aa2ff18b49773c288b91196009 Mon Sep 17 00:00:00 2001 From: Germano Guerrini Date: Fri, 2 Aug 2024 13:07:24 +0200 Subject: [PATCH 2/2] Updated version --- docs/source/changelog.rst | 4 ++++ docs/source/conf.py | 4 ++-- setup.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index b1b043e..8f66fe9 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +Version 2.18 +------------ +* Download URL computation has its own method + Version 2.17 ----------- * Added Conda-Forge repository diff --git a/docs/source/conf.py b/docs/source/conf.py index 8e76962..f9c8471 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -15,8 +15,8 @@ copyright = "2023, ECMWF" author = "ECMWF" -release = "2.17" -version = "2.17" +release = "2.18" +version = "2.18" # -- General configuration diff --git a/setup.py b/setup.py index 294c698..310381d 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def read(fname): return io.open(file_path, encoding="utf-8").read() -version = "2.17" +version = "2.18" setuptools.setup( name="hda",