From b594b88cfcdfdfd4380493e2bb33fdb2d4e97d5e Mon Sep 17 00:00:00 2001 From: mouffok Date: Thu, 30 May 2024 18:05:27 +0200 Subject: [PATCH 1/3] split file get call and property access --- kgforge/specializations/stores/bluebrain_nexus.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kgforge/specializations/stores/bluebrain_nexus.py b/kgforge/specializations/stores/bluebrain_nexus.py index 4b238c93..8571f655 100644 --- a/kgforge/specializations/stores/bluebrain_nexus.py +++ b/kgforge/specializations/stores/bluebrain_nexus.py @@ -465,12 +465,16 @@ def retrieve( query_params=query_params, ) - def _retrieve_filename(self, id_: str) -> Tuple[str, str]: + def _retrieve_file_metadata(self, id_: str) -> Dict: response = requests.get( id_, headers=self.service.headers, timeout=REQUEST_TIMEOUT ) catch_http_error_nexus(response, DownloadingError) metadata = response.json() + return metadata + + def _retrieve_filename(self, id_: str) -> Tuple[str, str]: + metadata = self._retrieve_file_metadata(id_) return metadata["_filename"], metadata["_mediaType"] def _download_many( From a87072ed4cc7618fe8451f27269460745a8e79e1 Mon Sep 17 00:00:00 2001 From: mouffok Date: Thu, 30 May 2024 18:12:03 +0200 Subject: [PATCH 2/3] split prepare download one --- .../specializations/stores/bluebrain_nexus.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/kgforge/specializations/stores/bluebrain_nexus.py b/kgforge/specializations/stores/bluebrain_nexus.py index 8571f655..9625a7d9 100644 --- a/kgforge/specializations/stores/bluebrain_nexus.py +++ b/kgforge/specializations/stores/bluebrain_nexus.py @@ -554,21 +554,7 @@ def _download_one( for chunk in response.iter_content(chunk_size=4096): f.write(chunk) - def _prepare_download_one( - self, url: str, store_metadata: Optional[DictWrapper], cross_bucket: bool - ) -> Tuple[str, str]: - if cross_bucket: - if store_metadata is not None: - project = store_metadata._project.split("/")[-1] - org = store_metadata._project.split("/")[-2] - else: - raise ValueError( - f"Downloading non registered file is not allowed when cross_bucket is set to {cross_bucket}" - ) - else: - org = self.service.organisation - project = self.service.project - + def _prepare_download_one_with_org_project(self, url: str, org: str, project: str): file_id = url.split("/")[-1] file_id = unquote(file_id) if len(file_id) < 1: @@ -590,6 +576,24 @@ def _prepare_download_one( ) return url_base, f"{org}/{project}" + def _prepare_download_one( + self, url: str, store_metadata: Optional[DictWrapper], cross_bucket: bool + ) -> Tuple[str, str]: + if cross_bucket: + if store_metadata is not None: + org, project = store_metadata._project.split("/") + else: + raise ValueError( + f"Downloading non registered file is not allowed when cross_bucket is set to True" + ) + else: + org = self.service.organisation + project = self.service.project + + return self._prepare_download_one_with_org_project(url, org, project) + + + # CR[U]D. def update( From 76f069dfcb5813bc315bc30d61d1f08ea039c77d Mon Sep 17 00:00:00 2001 From: Leonardo Cristella Date: Fri, 31 May 2024 12:23:06 +0200 Subject: [PATCH 3/3] lint --- kgforge/specializations/stores/bluebrain_nexus.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/kgforge/specializations/stores/bluebrain_nexus.py b/kgforge/specializations/stores/bluebrain_nexus.py index 9625a7d9..8580e4b5 100644 --- a/kgforge/specializations/stores/bluebrain_nexus.py +++ b/kgforge/specializations/stores/bluebrain_nexus.py @@ -592,8 +592,6 @@ def _prepare_download_one( return self._prepare_download_one_with_org_project(url, org, project) - - # CR[U]D. def update(