hrm_omero.formatting
Output formatting functions.
1"""Output formatting functions.""" 2 3import json 4 5from . import tree 6from .misc import printlog 7 8 9def tree_to_json(obj_tree): 10 """Create a JSON object with a given format from a tree. 11 12 Parameters 13 ---------- 14 obj_tree : list(dict) 15 The object tree as generated by `hrm_omero.tree.gen_children()`. 16 17 Returns 18 ------- 19 str 20 The JSON-formatted representation of the object tree. 21 """ 22 return json.dumps(obj_tree, sort_keys=True, indent=4, separators=(",", ": ")) 23 24 25def print_children_json(conn, omero_id): 26 """Print the child nodes of the given ID in JSON format. 27 28 Parameters 29 ---------- 30 conn : omero.gateway.BlitzGateway 31 The OMERO connection object. 32 omero_id : hrm_omero.misc.OmeroId 33 An object denoting an OMERO target. 34 35 Returns 36 ------- 37 bool 38 True in case printing the nodes was successful, False otherwise. 39 """ 40 try: 41 children = tree.gen_children(conn, omero_id) 42 except: # pylint: disable-msg=bare-except 43 printlog("ERROR", "ERROR generating OMERO tree / node!") 44 return False 45 print(tree_to_json(children)) 46 return True
def
tree_to_json(obj_tree):
10def tree_to_json(obj_tree): 11 """Create a JSON object with a given format from a tree. 12 13 Parameters 14 ---------- 15 obj_tree : list(dict) 16 The object tree as generated by `hrm_omero.tree.gen_children()`. 17 18 Returns 19 ------- 20 str 21 The JSON-formatted representation of the object tree. 22 """ 23 return json.dumps(obj_tree, sort_keys=True, indent=4, separators=(",", ": "))
Create a JSON object with a given format from a tree.
Parameters
- obj_tree (list(dict)):
The object tree as generated by
hrm_omero.tree.gen_children()
.
Returns
- str: The JSON-formatted representation of the object tree.
def
print_children_json(conn, omero_id):
26def print_children_json(conn, omero_id): 27 """Print the child nodes of the given ID in JSON format. 28 29 Parameters 30 ---------- 31 conn : omero.gateway.BlitzGateway 32 The OMERO connection object. 33 omero_id : hrm_omero.misc.OmeroId 34 An object denoting an OMERO target. 35 36 Returns 37 ------- 38 bool 39 True in case printing the nodes was successful, False otherwise. 40 """ 41 try: 42 children = tree.gen_children(conn, omero_id) 43 except: # pylint: disable-msg=bare-except 44 printlog("ERROR", "ERROR generating OMERO tree / node!") 45 return False 46 print(tree_to_json(children)) 47 return True
Print the child nodes of the given ID in JSON format.
Parameters
- conn (omero.gateway.BlitzGateway): The OMERO connection object.
- omero_id (hrm_omero.misc.OmeroId): An object denoting an OMERO target.
Returns
- bool: True in case printing the nodes was successful, False otherwise.