Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show root attrs in hsls #177

Merged
merged 2 commits into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading