Skip to content

Commit

Permalink
Merge pull request #317 from 4dn-dcic/dmichaels-misc-updates-20240823
Browse files Browse the repository at this point in the history
Minor changes to view-portal-object utility script.
  • Loading branch information
dmichaels-harvard authored Oct 7, 2024
2 parents e3da7e7 + 86bb150 commit e3eb8d9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dcicutils/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion dcicutils/scripts/view_portal_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
10 changes: 2 additions & 8 deletions dcicutils/structured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <support@4dnucleome.org>"]
license = "MIT"
Expand Down

0 comments on commit e3eb8d9

Please sign in to comment.