def _get_runable_prefix(cls, nodegraph, node): """Returns either 'R' or '+', dependening on the state of the node. If the node, or any of its subnodes, are runable, then 'R' is returned, otherwise '+' is returned. This is used to decorate the dependency graph.""" if nodegraph.get_node_state(node) in (cls.RUNNING, cls.RUNABLE): return "R" for subnode in node.subnodes: if nodegraph.get_node_state(subnode) in (cls.RUNNING, cls.RUNABLE): return "R" return "+"
def refresh(self, nodegraph): """See BaseUI.refresh.""" BaseUI.refresh(self, nodegraph) self._running_nodes = [] for node in nodegraph.iterflat(): if nodegraph.get_node_state(node) == self.RUNNING \ and not isinstance(node, MetaNode): self._running_nodes.append(node)
def inc_states(c_nodes, depth): for node in c_nodes: is_meta = isinstance(node, MetaNode) if depth and is_meta: inc_states(node.subnodes, depth - 1) elif meta or not is_meta: state = nodegraph.get_node_state(node) states[state] += 1 if state == nodegraph.RUNNING: threads.append(node.threads) return states
def _count_states(cls, nodegraph, nodes): """Counts the number of each state observed for a set of nodes, and returns these as a list, as well as the estimated number of threads being used by running nodes. If 'meta' is true, these are considered to be the subnodes of a MetaNode; in that case, MetaNode(s) themselves are not counted, but their subnodes are counted for the first level encountered.""" states = [0] * nodegraph.NUMBER_OF_STATES threads = 0 for node in nodes: if not isinstance(node, MetaNode): state = nodegraph.get_node_state(node) states[state] += 1 if state == nodegraph.RUNNING: threads += node.threads return states, threads
def _print_sub_nodes(cls, nodegraph, nodes, prefix=" "): _grouper = lambda node: (nodegraph.get_node_state(node) != cls.DONE) viable_nodes, dead_nodes = group_by_pred(_grouper, nodes) viable_nodes.sort(key=str) for node in viable_nodes: runable = cls._get_runable_prefix(nodegraph, node) description = "%s%s %s" % (prefix, runable, node) if node.subnodes: states, threads \ = cls._count_states(nodegraph, node.subnodes, True) description = "%s (%s)" \ % (description, cls._describe_states(states, threads)) print_func = cls._get_print_function(nodegraph, node) print_func(description) is_last_node = (node == viable_nodes[-1]) and not dead_nodes current_prefix = prefix + (" " if is_last_node else "| ") if node.dependencies: if cls._collapse_node(nodegraph, node.dependencies): description = "+ %i dependencies hidden ..." \ % cls._count_dependencies(node.dependencies | node.subnodes) print_disabled(current_prefix + description) print_disabled(current_prefix) else: cls._print_sub_nodes(nodegraph, node.dependencies, current_prefix + " ") else: print_func(current_prefix) if dead_nodes: print_disabled(prefix + "+ %i dependencies hidden ..." % cls._count_dependencies(dead_nodes)) print_disabled(prefix)