From 2539c5ff126e4544935a4e11e7fdf6ccaa83468f Mon Sep 17 00:00:00 2001 From: David Michaels Date: Thu, 22 Aug 2024 07:14:20 -0400 Subject: [PATCH] Added portal_utils.Portal.head method --- CHANGELOG.rst | 7 +++++++ dcicutils/portal_utils.py | 11 +++++++++++ pyproject.toml | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f867ea7b6..6664c0284 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,13 @@ dcicutils Change Log ---------- +8.14.3 +====== + +* 2024-08-22 (dmichaels) +* Added portal_utils.Portal.head method. + + 8.14.2 ====== * Corrected requests version (to ^2.27.0 from 2.31.0) on pyproject.toml to not be pinned; but doing diff --git a/dcicutils/portal_utils.py b/dcicutils/portal_utils.py index 0f0bba5e8..c73d565b6 100644 --- a/dcicutils/portal_utils.py +++ b/dcicutils/portal_utils.py @@ -280,6 +280,17 @@ def post_metadata(self, object_type: str, data: dict, check_only: bool = False) add_on="check_only=True" if check_only else "") return self.post(f"/{object_type}{'?check_only=True' if check_only else ''}", data).json() + def head(self, url: str, follow: bool = False, raise_exception: bool = False, **kwargs) -> Optional[int]: + try: + response = requests.head(self.url(url), **self._kwargs(**kwargs)) + if response and response.status_code in [301, 302, 303, 307, 308] and (follow is True): + response = response.follow() + return response.status_code + except Exception as e: + if raise_exception is True: + raise e + return None + def get_health(self) -> OptionalResponse: return self.get("/health") diff --git a/pyproject.toml b/pyproject.toml index 630a224fd..33e115f58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "8.14.2" +version = "8.14.2.1b1" # TODO: To become 8.14.3 description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT"