Exemplo n.º 1
0
    def node_strings_from_graph(cls, config, graph):
        """
        Generates print information about nodes in graph.
        Starts from the roots of the graph.

        :param LineArrangementsConfig: config
        :param `DiGraph` graph: the graph

        :returns: a table of information to be used for further display
        :rtype: list of dict of str * object

        Fields in table:
        * diffstatus - the diffstatus of the edge to this node
        * indent - the level of indentation
        * last - whether this node is the last child of its parent
        * node - the table of information about the node itself
        * orphan - whether this node has no parents
        """
        roots = sorted(
           GraphUtils.get_roots(graph),
           key=SortingUtils.str_key_func_gen(
              lambda n: config.info_func(n, [config.sort_key])[config.sort_key]
           )
        )

        def node_func(node):
            """
            A function that returns the line arrangements for a root node.
            """
            return cls.node_strings_from_root(
               config,
               graph,
               node
            )

        return [l for root in roots for l in node_func(root)]
Exemplo n.º 2
0
    def node_strings(
       cls,
       config,
       graph,
       orphan,
       last,
       diffstatus,
       indent,
       node
    ):
        """
        Generates print information about nodes reachable from
        ``node`` including itself.

        :param LineArrangementsConfig: config
        :param `DiGraph` graph: the graph
        :param bool orphan: True if this node has no parents, otherwise False
        :param bool last: True if this node is the last child, otherwise False
        :param `DiffStatus` diffstatus: the diffstatus of the edge
        :param int indent: the indentation level
        :param `Node` node: the node to print

        :returns: a table of information to be used for further display
        :rtype: dict of str * object

        Fields in table:
        * diffstatus - the diffstatus of the edge to this node
        * indent - the level of indentation
        * last - whether this node is the last child of its parent
        * node - the table of information about the node itself
        * orphan - whether this node has no parents
        """
        # pylint: disable=too-many-arguments
        yield {
           'diffstatus' : diffstatus,
           'indent' : indent,
           'last' : last,
           'node' : config.info_func(node, keys=None, conv=config.conversion_func),
           'orphan' : orphan,
        }


        successors = sorted(
           graph.successors(node),
           key=SortingUtils.str_key_func_gen(
              lambda x: config.info_func(x, [config.sort_key])[config.sort_key]
           )
        )

        for succ in successors:
            lines = cls.node_strings(
               config,
               graph,
               False,
               succ is successors[-1],
               graph[node][succ].get('diffstatus'),
               indent if orphan else indent + 1,
               succ
            )
            for line in lines:
                yield line