From 351ae4f408f327def14b13c653a82a5e96278ee0 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 23 Oct 2009 05:19:59 +0000 Subject: [PATCH] Add a --unordered-display option for use with --tree. This allows the display to be optimized differently since the merge order is not preserved. Thanks to Sebastian Mingramm (few) for the initial patch. svn path=/main/trunk/; revision=14703 --- man/emerge.1 | 6 ++++++ pym/_emerge/Scheduler.py | 11 ++++++++--- pym/_emerge/actions.py | 10 ++++++++-- pym/_emerge/depgraph.py | 39 +++++++++++++++++++++++++++++++++++++-- pym/_emerge/main.py | 1 + 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/man/emerge.1 b/man/emerge.1 index 34fbe6459..bcdc747ca 100644 --- a/man/emerge.1 +++ b/man/emerge.1 @@ -226,6 +226,12 @@ system. Its arguments can be \fIatoms\fR or \fIebuilds\fR. For a dependency aware version of \fB\-\-unmerge\fR, use \fB\-\-depclean\fR or \fB\-\-prune\fR. .TP +.BR "\-\-unordered-display " +By default the displayed merge list is sorted using the order in +which the packages will be merged. When \fB\-\-tree\fR is used together +with this option, this constraint is removed, hopefully leading to a +more readable dependency tree. +.TP .BR "\-\-update " (\fB\-u\fR) Updates packages to the best version available, which may not always be the highest version number due to masking for testing and development. diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index c95003dd7..4fcb9fc05 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1492,9 +1492,14 @@ class Scheduler(PollScheduler): if self._show_list(): if "--tree" in self.myopts: - portage.writemsg_stdout("\n" + \ - darkgreen("These are the packages that " + \ - "would be merged, in reverse order:\n\n")) + if "--unordered-display" in self.myopts: + portage.writemsg_stdout("\n" + \ + darkgreen("These are the packages that " + \ + "would be merged:") + "\n\n") + else: + portage.writemsg_stdout("\n" + \ + darkgreen("These are the packages that " + \ + "would be merged, in reverse order:") + "\n\n") else: portage.writemsg_stdout("\n" + \ diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 24617a7cf..ea7f241a8 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -176,8 +176,14 @@ def action_build(settings, trees, mtimedb, else: action = "merged" if "--tree" in myopts and action != "fetched": # Tree doesn't work with fetching - print() - print(darkgreen("These are the packages that would be %s, in reverse order:") % action) + if "--unordered-display" in myopts: + portage.writemsg_stdout("\n" + \ + darkgreen("These are the packages that " + \ + "would be %s:" % action) + "\n\n") + else: + portage.writemsg_stdout("\n" + \ + darkgreen("These are the packages that " + \ + "would be %s, in reverse order:" % action) + "\n\n") print() else: print() diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 74f79b3c9..e79c74471 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -4534,6 +4534,40 @@ class depgraph(object): for blocker in uninstall_parents: mygraph.add(upgrade_node, blocker) + if "--unordered-display" in self._frozen_config.myopts: + display_list = self._unordered_tree_display(mygraph, mylist) + else: + display_list = self._ordered_tree_display(mygraph, mylist) + + self._prune_tree_display(display_list) + + return display_list + + def _unordered_tree_display(self, mygraph, mylist): + display_list = [] + seen_nodes = set() + + def print_node(node, depth): + + if node in seen_nodes: + pass + else: + seen_nodes.add(node) + + if isinstance(node, Package): + display_list.append((node, depth, True)) + else: + depth = -1 + + for child_node in mygraph.child_nodes(node): + print_node(child_node, depth + 1) + + for root_node in mygraph.root_nodes(): + print_node(root_node, 0) + + return display_list + + def _ordered_tree_display(self, mygraph, mylist): depth = 0 shown_edges = set() tree_nodes = [] @@ -4594,6 +4628,9 @@ class depgraph(object): tree_nodes = [] add_parents(x, True) + return display_list + + def _prune_tree_display(self, display_list): last_merge_depth = 0 for i in range(len(display_list) - 1, -1, -1): node, depth, ordered = display_list[i] @@ -4613,8 +4650,6 @@ class depgraph(object): depth >= display_list[i+1][1]: del display_list[i] - return display_list - def display_problems(self): """ Display problems with the dependency graph such as slot collisions. diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py index 92a6d491f..b00c8fb17 100644 --- a/pym/_emerge/main.py +++ b/pym/_emerge/main.py @@ -66,6 +66,7 @@ options=[ "--searchdesc", "--skipfirst", "--tree", +"--unordered-display", "--update", "--verbose", ] -- 2.26.2