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
Returns
  • str: The JSON-formatted representation of the object tree.