From 242628112a797c35ad3b3163a53e2f051f29d47a Mon Sep 17 00:00:00 2001 From: John Readey Date: Wed, 27 Mar 2024 12:23:18 -0700 Subject: [PATCH] show root attrs in hsls (#177) * show root attrs in hsls * fix flake8 errors --- h5pyd/_apps/hsls.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/h5pyd/_apps/hsls.py b/h5pyd/_apps/hsls.py index 1b234f5..e566ac9 100644 --- a/h5pyd/_apps/hsls.py +++ b/h5pyd/_apps/hsls.py @@ -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 @@ -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"] @@ -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