From ed138969fab99cc36e6476ccda3ef592976a4e80 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 19 Sep 2006 06:46:41 +0000 Subject: This is a new --tree implementation by Jason Stubbs, from bug #147766. svn path=/main/trunk/; revision=4479 --- pym/portage.py | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'pym/portage.py') diff --git a/pym/portage.py b/pym/portage.py index d4f235873..bc4aee45d 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -397,6 +397,23 @@ class digraph: leaf_nodes.append(node) return leaf_nodes + def root_nodes(self, ignore_soft_deps=False): + """Return all nodes that have no parents. + + If ignore_soft_deps is True, soft deps are not counted as + parents in calculations.""" + + root_nodes = [] + for node in self.order: + is_root_node = True + for parent in self.nodes[node][1]: + if not (ignore_soft_deps and self.nodes[node][1][parent]): + is_root_node = False + break + if is_root_node: + root_nodes.append(node) + return root_nodes + def is_empty(self): """Checks if the digraph is empty""" return len(self.nodes) == 0 @@ -430,29 +447,6 @@ class digraph: def hasallzeros(self): return len(self.leaf_nodes() == 0) - def depth(self, node): - """Find how many nodes are in the parent chain of the passed node - - This method doesn't make sense unless there is no more than one - parent for each node. As this digraph is capable of having multiple - parents on a node, this implementation chooses an arbitrary parent - for calculations, stopping as soon as a loop is detected in order - to mimic the sorts of counts that would have previously been - returned. - - This method is only used by emerge's --tree option. That option - needs to be reworked to not use this so that this method can be - removed altogether.""" - - parents = {} - while self.nodes[node][1]: - parent = self.nodes[node][1].keys()[0] - if parent in parents: - break - parents[parent] = True - node = parent - return len(parents) - def debug_print(self): for node in self.nodes: print node, -- cgit v1.2.3-1-g7c22