Skip to content

Commit

Permalink
show root attrs in hsls (#177)
Browse files Browse the repository at this point in the history
* show root attrs in hsls

* fix flake8 errors
  • Loading branch information
jreadey authored Mar 27, 2024
1 parent 15c97f3 commit 2426281
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions h5pyd/_apps/hsls.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,7 @@ def dump(name, obj, visited=None):

if cfg["showattrs"] and class_name in ("Dataset", "Table", "Group", "Datatype"):
# dump attributes for the object
for attr_name in obj.attrs:
attr = obj.attrs[attr_name]
el = "..." # show this if the attribute is too large
if isinstance(attr, np.ndarray):
rank = len(attr.shape)
else:
rank = 0 # scalar data
if rank > 1:
val = "[" * rank + el + "]" * rank
print(" attr: {0:24} {1}".format(attr_name, val))
elif rank == 1 and attr.shape[0] > 1:
val = "[{},{}]".format(attr[0], el)
print(" attr: {0:24} {1}".format(attr_name, val))
else:
print(" attr: {0:24} {1}".format(attr_name, attr))
dumpAttrs(obj)

if visited is not None and obj_id is not None:
visited[obj_id] = name
Expand Down Expand Up @@ -290,6 +276,26 @@ def dumpAcls(obj):
dumpACL(acl)


def dumpAttrs(obj):
""" print attributes of the given obj """

for attr_name in obj.attrs:
attr = obj.attrs[attr_name]
el = "..." # show this if the attribute is too large
if isinstance(attr, np.ndarray):
rank = len(attr.shape)
else:
rank = 0 # scalar data
if rank > 1:
val = "[" * rank + el + "]" * rank
print(" attr: {0:24} {1}".format(attr_name, val))
elif rank == 1 and attr.shape[0] > 1:
val = "[{},{}]".format(attr[0], el)
print(" attr: {0:24} {1}".format(attr_name, val))
else:
print(" attr: {0:24} {1}".format(attr_name, attr))


def getFolder(domain):
username = cfg["hs_username"]
password = cfg["hs_password"]
Expand Down Expand Up @@ -652,6 +658,10 @@ def main():
dump(h5path, obj)
continue

if cfg["showattrs"]:
# dump attributes for root group
dumpAttrs(grp)

if depth < 0:
# recursive
visited = {} # dict of id to h5path
Expand Down

0 comments on commit 2426281

Please sign in to comment.