depgraph.display(): handle reverse for --tree
authorZac Medico <zmedico@gentoo.org>
Sat, 1 Jun 2013 00:16:34 +0000 (17:16 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 1 Jun 2013 00:16:34 +0000 (17:16 -0700)
This factors --tree logic out of the calling code, and allows
optimization of _show_merge_list to use reference comparison instead
of == comparison. Also, deprecate the unused depgraph.altlist()
"reversed" parameter, due to builtin name collision.

pym/_emerge/Scheduler.py
pym/_emerge/actions.py
pym/_emerge/depgraph.py
pym/_emerge/resolver/circular_dependency.py

index 4e8b223fb51c575232c0670b41423f0b0a0f7636..94d3d3f529b2661278cc4ee0d2447179fe43e7de 100644 (file)
@@ -1827,11 +1827,7 @@ class Scheduler(PollScheduler):
                        return False
 
                if success and self._show_list():
-                       mylist = mydepgraph.altlist()
-                       if mylist:
-                               if "--tree" in self.myopts:
-                                       mylist = tuple(reversed(mylist))
-                               mydepgraph.display(mylist, favorites=self._favorites)
+                       mydepgraph.display(mydepgraph.altlist(), favorites=self._favorites)
 
                if not success:
                        self._post_mod_echo_msgs.append(mydepgraph.display_problems)
index 7b2cf54a5b7b76294346faaaa132d1f9a2c3093d..d6e810084bd18ea3a1b68a612c40744e22afd5e8 100644 (file)
@@ -336,7 +336,7 @@ def action_build(settings, trees, mtimedb,
                                return os.EX_OK
                        favorites = mtimedb["resume"]["favorites"]
                        retval = mydepgraph.display(
-                               mydepgraph.altlist(reversed=tree),
+                               mydepgraph.altlist(),
                                favorites=favorites)
                        mydepgraph.display_problems()
                        mergelist_shown = True
@@ -345,7 +345,7 @@ def action_build(settings, trees, mtimedb,
                        prompt="Would you like to resume merging these packages?"
                else:
                        retval = mydepgraph.display(
-                               mydepgraph.altlist(reversed=("--tree" in myopts)),
+                               mydepgraph.altlist(),
                                favorites=favorites)
                        mydepgraph.display_problems()
                        mergelist_shown = True
@@ -404,7 +404,7 @@ def action_build(settings, trees, mtimedb,
                                return os.EX_OK
                        favorites = mtimedb["resume"]["favorites"]
                        retval = mydepgraph.display(
-                               mydepgraph.altlist(reversed=tree),
+                               mydepgraph.altlist(),
                                favorites=favorites)
                        mydepgraph.display_problems()
                        mergelist_shown = True
@@ -412,7 +412,7 @@ def action_build(settings, trees, mtimedb,
                                return retval
                else:
                        retval = mydepgraph.display(
-                               mydepgraph.altlist(reversed=("--tree" in myopts)),
+                               mydepgraph.altlist(),
                                favorites=favorites)
                        mydepgraph.display_problems()
                        mergelist_shown = True
index 9c0a966c557f452ec3bbb26e36f786f092567401..3e29508c729c6301c8c06f45b0f51f9b8a61644f 100644 (file)
@@ -9,6 +9,7 @@ import logging
 import stat
 import sys
 import textwrap
+import warnings
 from collections import deque
 from itertools import chain
 
@@ -5694,7 +5695,12 @@ class depgraph(object):
 
                mygraph.order.sort(key=cmp_sort_key(cmp_merge_preference))
 
-       def altlist(self, reversed=False):
+       def altlist(self, reversed=DeprecationWarning):
+
+               if reversed is not DeprecationWarning:
+                       warnings.warn("The reversed parameter of "
+                               "_emerge.depgraph.depgraph.altlist() is deprecated",
+                               DeprecationWarning, stacklevel=2)
 
                while self._dynamic_config._serialized_tasks_cache is None:
                        self._resolve_conflicts()
@@ -5705,8 +5711,8 @@ class depgraph(object):
                                pass
 
                retlist = self._dynamic_config._serialized_tasks_cache
-               if reversed:
-                       # TODO: deprecate the "reversed" parameter (builtin name collision)
+               if reversed is not DeprecationWarning and reversed:
+                       # TODO: remove the "reversed" parameter (builtin name collision)
                        retlist = list(retlist)
                        retlist.reverse()
                        retlist = tuple(retlist)
@@ -6647,14 +6653,8 @@ class depgraph(object):
        def _show_merge_list(self):
                if self._dynamic_config._serialized_tasks_cache is not None and \
                        not (self._dynamic_config._displayed_list is not None and \
-                       (self._dynamic_config._displayed_list is self._dynamic_config._serialized_tasks_cache or \
-                       self._dynamic_config._displayed_list == self._dynamic_config._serialized_tasks_cache or \
-                       self._dynamic_config._displayed_list == \
-                               list(reversed(self._dynamic_config._serialized_tasks_cache)))):
-                       display_list = self._dynamic_config._serialized_tasks_cache
-                       if "--tree" in self._frozen_config.myopts:
-                               display_list = tuple(reversed(display_list))
-                       self.display(display_list)
+                       self._dynamic_config._displayed_list is self._dynamic_config._serialized_tasks_cache):
+                       self.display(self._dynamic_config._serialized_tasks_cache)
 
        def _show_unsatisfied_blockers(self, blockers):
                self._show_merge_list()
@@ -6749,6 +6749,10 @@ class depgraph(object):
                # redundantly displaying this exact same merge list
                # again via _show_merge_list().
                self._dynamic_config._displayed_list = mylist
+
+               if "--tree" in self._frozen_config.myopts:
+                       mylist = tuple(reversed(mylist))
+
                display = Display()
 
                return display(self, mylist, favorites, verbosity)
index 6380b22c7fe216bed8fb89fc53fb9b082d8c232f..b7106714a945ed788dc28708313b416fa4a61d69 100644 (file)
@@ -62,8 +62,7 @@ class circular_dependency_handler(object):
                                node = nodes[0]
                        display_order.append(node)
                        tempgraph.remove(node)
-               display_order.reverse()
-               return display_order
+               return tuple(display_order)
 
        def _prepare_circular_dep_message(self):
                """