diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0314eb0f6..297ce913f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,15 @@ dcicutils Change Log ---------- +8.16.0 +====== + +* Minor changes to view_portal_object utility script. +* Minor changes to validators hooks in structured_data. +* Added portal_utils.Portal.get_version method. +* Minor fix in misc_utils.format_duration. + + 8.15.0 ====== * 2024-10-04 (dmichaels) diff --git a/dcicutils/misc_utils.py b/dcicutils/misc_utils.py index 5de86755e..2df638862 100644 --- a/dcicutils/misc_utils.py +++ b/dcicutils/misc_utils.py @@ -2802,7 +2802,7 @@ def format_duration(seconds: Union[int, float]) -> str: durations = [("year", 31536000), ("day", 86400), ("hour", 3600), ("minute", 60), ("second", 1)] parts = [] for name, duration in durations: - if seconds >= duration: + if (seconds == 0) or (seconds >= duration): count = seconds // duration seconds %= duration if count != 1: diff --git a/dcicutils/portal_utils.py b/dcicutils/portal_utils.py index ce92c9270..3467cf19f 100644 --- a/dcicutils/portal_utils.py +++ b/dcicutils/portal_utils.py @@ -294,6 +294,12 @@ def head(self, url: str, follow: bool = True, raise_exception: bool = False, **k def get_health(self) -> OptionalResponse: return self.get("/health") + def get_version(self) -> Optional[str]: + try: + return self.get_health().json()["project_version"] + except Exception: + return None + def ping(self) -> bool: try: return self.get_health().status_code == 200 diff --git a/dcicutils/scripts/view_portal_object.py b/dcicutils/scripts/view_portal_object.py index 8696c94b6..7d440df2e 100644 --- a/dcicutils/scripts/view_portal_object.py +++ b/dcicutils/scripts/view_portal_object.py @@ -360,7 +360,12 @@ def write_insert_files(response: dict) -> None: path = f"/{uuid}" else: path = uuid - response = portal.get(path, raw=raw or inserts, database=database) + if (response := portal.get(path, raw=raw or inserts, database=database)) is not None: + if response.status_code == 403: + _exit(f"Permission error getting Portal object from {portal.server}: {uuid}") + elif response.status_code == 404: + _exit(f"Not found Portal object from {portal.server}: {uuid}") + except Exception as e: if "404" in str(e) and "not found" in str(e).lower(): _print(f"Portal object not found at {portal.server}: {uuid}") diff --git a/dcicutils/structured_data.py b/dcicutils/structured_data.py index 945723040..fa2ae7d52 100644 --- a/dcicutils/structured_data.py +++ b/dcicutils/structured_data.py @@ -318,7 +318,7 @@ def get_counts() -> Tuple[int, int]: order = {Schema.type_name(key): index for index, key in enumerate(self._order)} if self._order else {} for sheet_name in sorted(excel.sheet_names, key=lambda key: order.get(Schema.type_name(key), sys.maxsize)): self._load_reader(excel.sheet_reader(sheet_name), type_name=Schema.type_name(sheet_name)) - if self._validator_sheet_hook: + if self._validator_sheet_hook and self.data.get(sheet_name): self._validator_sheet_hook(self, sheet_name, self.data[sheet_name]) # TODO: Do we really need progress reporting for the below? # Check for unresolved reference errors which really are not because of ordering. @@ -388,13 +388,7 @@ def _load_reader(self, reader: RowReader, type_name: str) -> None: structured_row = structured_row_template.create_row() for column_name, value in row.items(): if self._validator_hook: - value, validator_error = ( - self._validator_hook(self, type_name, column_name, reader.row_number, value)) - if validator_error: - self._note_error({ - "src": create_dict(type=schema_name, row=reader.row_number), - "error": validator_error - }, "validation") + value = self._validator_hook(self, type_name, column_name, reader.row_number, value) structured_row_template.set_value(structured_row, column_name, value, reader.file, reader.row_number) if self._autoadd_properties: self._add_properties(structured_row, self._autoadd_properties, schema) diff --git a/pyproject.toml b/pyproject.toml index 24dc1c42f..ac6809802 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "8.15.0" +version = "8.16.0" description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT"