Factor out duplicate "These are the packages that would be merged",
authorZac Medico <zmedico@gentoo.org>
Sat, 24 Oct 2009 07:04:54 +0000 (07:04 -0000)
committerZac Medico <zmedico@gentoo.org>
Sat, 24 Oct 2009 07:04:54 +0000 (07:04 -0000)
"Calculating dependencies", and spinner cleanup code. (trunk r14704)

svn path=/main/branches/2.1.7/; revision=14713

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

index db1aecc79a0beb5dafe863082546d5b319355eca..598ab659e30fcf5ea99f6afd0cb8721794081929 100644 (file)
@@ -1490,28 +1490,6 @@ class Scheduler(PollScheduler):
                """
                print(colorize("GOOD", "*** Resuming merge..."))
 
-               if self._show_list():
-                       if "--tree" in self.myopts:
-                               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" + \
-                                       darkgreen("These are the packages that " + \
-                                       "would be merged, in order:\n\n"))
-
-               show_spinner = "--quiet" not in self.myopts and \
-                       "--nodeps" not in self.myopts
-
-               if show_spinner:
-                       print("Calculating dependencies  ", end=' ')
-
                myparams = create_depgraph_params(self.myopts, None)
                success = False
                e = None
@@ -1527,9 +1505,6 @@ class Scheduler(PollScheduler):
                        mydepgraph = e.depgraph
                        dropped_tasks = set()
 
-               if show_spinner:
-                       print("\b\b... done!")
-
                if e is not None:
                        def unsatisfied_resume_dep_msg():
                                mydepgraph.display_problems()
index f8b5346a6ee585499731d4ba1395e35997b908fd..ee37bec6dec28f43e536084a2b3c7db89eba4129 100644 (file)
@@ -165,42 +165,10 @@ def action_build(settings, trees, mtimedb,
                        writemsg("%s%s\n" % (prefix, line))
                writemsg(prefix + "\n")
 
-       if "--quiet" not in myopts and \
-               ("--pretend" in myopts or "--ask" in myopts or \
-               "--tree" in myopts or "--verbose" in myopts):
-               action = ""
-               if "--fetchonly" in myopts or "--fetch-all-uri" in myopts:
-                       action = "fetched"
-               elif "--buildpkgonly" in myopts:
-                       action = "built"
-               else:
-                       action = "merged"
-               if "--tree" in myopts and action != "fetched": # Tree doesn't work with fetching
-                       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()
-                       print(darkgreen("These are the packages that would be %s, in order:") % action)
-                       print()
-
-       show_spinner = "--quiet" not in myopts and "--nodeps" not in myopts
-       if not show_spinner:
-               spinner.update = spinner.update_quiet
-
        if resume:
                favorites = mtimedb["resume"].get("favorites")
                if not isinstance(favorites, list):
                        favorites = []
-
-               if show_spinner:
-                       print("Calculating dependencies  ", end=' ')
                myparams = create_depgraph_params(myopts, myaction)
 
                resume_data = mtimedb["resume"]
@@ -221,8 +189,7 @@ def action_build(settings, trees, mtimedb,
                        depgraph.UnsatisfiedResumeDep) as e:
                        if isinstance(e, depgraph.UnsatisfiedResumeDep):
                                mydepgraph = e.depgraph
-                       if show_spinner:
-                               print()
+
                        from textwrap import wrap
                        from portage.output import EOutput
                        out = EOutput()
@@ -274,9 +241,6 @@ def action_build(settings, trees, mtimedb,
                                        "the operation manually."
                                for line in wrap(msg, 72):
                                        out.eerror(line)
-               else:
-                       if show_spinner:
-                               print("\b\b... done!")
 
                if success:
                        if dropped_tasks:
@@ -304,24 +268,15 @@ def action_build(settings, trees, mtimedb,
                        print(darkgreen("emerge: It seems we have nothing to resume..."))
                        return os.EX_OK
 
-               if "--quiet" not in myopts and "--nodeps" not in myopts:
-                       print("Calculating dependencies  ", end=' ')
-                       sys.stdout.flush()
-
                myparams = create_depgraph_params(myopts, myaction)
                try:
                        success, mydepgraph, favorites = backtrack_depgraph(
                                settings, trees, myopts, myparams, myaction, myfiles, spinner)
                except portage.exception.PackageSetNotFound as e:
-                       if show_spinner:
-                               print("\b\b... done!")
                        root_config = trees[settings["ROOT"]]["root_config"]
                        display_missing_pkg_set(root_config, e.value)
                        return 1
 
-               if show_spinner:
-                       print("\b\b... done!")
-
                if not success:
                        mydepgraph.display_problems()
                        return 1
index 859bda1532dee83680838f1dc0e00f7bb0d19781..e1e04d9b92417777d8c9654054f51bd721643c6c 100644 (file)
@@ -5247,11 +5247,62 @@ def insert_category_into_atom(atom, category):
                ret = None
        return ret
 
+def _spinner_start(spinner, myopts):
+       if spinner is None:
+               return
+       if "--quiet" not in myopts and \
+               ("--pretend" in myopts or "--ask" in myopts or \
+               "--tree" in myopts or "--verbose" in myopts):
+               action = ""
+               if "--fetchonly" in myopts or "--fetch-all-uri" in myopts:
+                       action = "fetched"
+               elif "--buildpkgonly" in myopts:
+                       action = "built"
+               else:
+                       action = "merged"
+               if "--tree" in myopts and action != "fetched": # Tree doesn't work with fetching
+                       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")
+               else:
+                       portage.writemsg_stdout("\n" + \
+                               darkgreen("These are the packages that " + \
+                               "would be %s, in order:" % action) + "\n\n")
+
+       show_spinner = "--quiet" not in myopts and "--nodeps" not in myopts
+       if not show_spinner:
+               spinner.update = spinner.update_quiet
+
+       if show_spinner:
+               portage.writemsg_stdout("Calculating dependencies  ")
+
+def _spinner_stop(spinner):
+       if spinner is None or \
+               spinner.update is spinner.update_quiet:
+               return
+
+       portage.writemsg_stdout("\b\b... done!\n")
+
 def backtrack_depgraph(settings, trees, myopts, myparams, 
        myaction, myfiles, spinner):
        """
        Raises PackageSetNotFound if myfiles contains a missing package set.
        """
+       _spinner_start(spinner, myopts)
+       try:
+               return _backtrack_depgraph(settings, trees, myopts, myparams, 
+                       myaction, myfiles, spinner)
+       finally:
+               _spinner_stop(spinner)
+
+def _backtrack_depgraph(settings, trees, myopts, myparams, 
+       myaction, myfiles, spinner):
+
        backtrack_max = 30
        runtime_pkg_mask = None
        allow_backtracking = True
@@ -5284,6 +5335,17 @@ def backtrack_depgraph(settings, trees, myopts, myparams,
        return (success, mydepgraph, favorites)
 
 def resume_depgraph(settings, trees, mtimedb, myopts, myparams, spinner):
+       """
+       Raises PackageSetNotFound if myfiles contains a missing package set.
+       """
+       _spinner_start(spinner, myopts)
+       try:
+               return _resume_depgraph(settings, trees, mtimedb, myopts,
+                       myparams, spinner)
+       finally:
+               _spinner_stop(spinner)
+
+def _resume_depgraph(settings, trees, mtimedb, myopts, myparams, spinner):
        """
        Construct a depgraph for the given resume list. This will raise
        PackageNotFound or depgraph.UnsatisfiedResumeDep when necessary.