From 7ba1322dfdb4cc8f04de0c89105d738b3f6df68b Mon Sep 17 00:00:00 2001 From: David Michaels Date: Wed, 14 Aug 2024 13:12:21 -0400 Subject: [PATCH] Minor changes to utility/troubleshooting/convenience script view-portal-object. --- CHANGELOG.rst | 5 +++++ dcicutils/scripts/view_portal_object.py | 24 +++++++++++++++++++++--- pyproject.toml | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d934d7947..c3d025357 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,11 @@ dcicutils Change Log ---------- +8.14.1 +====== +* Minor changes to utility/troubleshooting/convenience script view-portal-object. + + 8.14.0 ====== * Minor updates to the view-portal-object dev/troubleshooting utility script. diff --git a/dcicutils/scripts/view_portal_object.py b/dcicutils/scripts/view_portal_object.py index 90f459303..e0d1dd3ba 100644 --- a/dcicutils/scripts/view_portal_object.py +++ b/dcicutils/scripts/view_portal_object.py @@ -279,13 +279,31 @@ def _get_portal_object(portal: Portal, uuid: str, if not ((supertypes := portal.get_schemas_super_type_map()) and (subtypes := supertypes.get(results_type))): subtypes = None response = {} + results_index = 0 + results_total = len(results) + def get_metadata_for_individual_result_type(uuid: str) -> Optional[dict]: # noqa + # There can be a lot of individual results for which we may need to get the actual type, + # so do this in a function we were can give verbose output feedback. + nonlocal portal, results_index, results_total, verbose + if verbose: + _print(f"Getting actual type for {results_type} result:" + f" {uuid} [{results_index} of {results_total}]", end="") + result = portal.get_metadata(uuid, raise_exception=False) + if (isinstance(result_types := result.get("@type"), list) and + result_types and (result_type := result_types[0])): # noqa + if verbose: + _print(f" -> {result_type}") + return result_type + if verbose: + _print() + return None for result in results: + results_index += 1 result.pop("schema_version", None) if (subtypes and (result_uuid := result.get("uuid")) and - (individual_result := portal.get_metadata(result_uuid, raise_exception=False)) and - isinstance(result_type:= individual_result.get("@type"), list) and result_type and result_type[0]): # noqa - result_type = result_type[0] + (individual_result_type := get_metadata_for_individual_result_type(result_uuid))): # noqa + result_type = individual_result_type else: result_type = results_type if response.get(result_type): diff --git a/pyproject.toml b/pyproject.toml index c47099bb5..5c1783817 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcicutils" -version = "8.14.0" +version = "8.14.0.1b1" # TODO: To become 8.14.1 description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources" authors = ["4DN-DCIC Team "] license = "MIT"