Tweak "add to world" prompt, bug #455946.
authorZac Medico <zmedico@gentoo.org>
Fri, 8 Feb 2013 16:29:05 +0000 (08:29 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 8 Feb 2013 16:29:05 +0000 (08:29 -0800)
pym/_emerge/actions.py
pym/_emerge/depgraph.py

index a95d7a1c5f6776d42715ed117123ec2899ee0032..0776f7b911a56647ebf3cbae61a2ab41d519d4da 100644 (file)
@@ -325,6 +325,7 @@ def action_build(settings, trees, mtimedb,
                        mydepgraph.display_problems()
                        return 1
 
+       mergecount = None
        if "--pretend" not in myopts and \
                ("--ask" in myopts or "--tree" in myopts or \
                "--verbose" in myopts) and \
@@ -356,6 +357,7 @@ def action_build(settings, trees, mtimedb,
                                if isinstance(x, Package) and x.operation == "merge":
                                        mergecount += 1
 
+                       prompt = None
                        if mergecount==0:
                                sets = trees[settings['EROOT']]['root_config'].sets
                                world_candidates = None
@@ -368,12 +370,11 @@ def action_build(settings, trees, mtimedb,
                                        world_candidates = [x for x in favorites \
                                                if not (x.startswith(SETPREFIX) and \
                                                not sets[x[1:]].world_candidate)]
+
                                if "selective" in myparams and \
                                        not oneshot and world_candidates:
-                                       print()
-                                       for x in world_candidates:
-                                               print(" %s %s" % (good("*"), x))
-                                       prompt="Would you like to add these packages to your world favorites?"
+                                       # Prompt later, inside saveNomergeFavorites.
+                                       prompt = None
                                elif settings["AUTOCLEAN"] and "yes"==settings["AUTOCLEAN"]:
                                        prompt="Nothing to merge; would you like to auto-clean packages?"
                                else:
@@ -386,13 +387,15 @@ def action_build(settings, trees, mtimedb,
                        else:
                                prompt="Would you like to merge these packages?"
                print()
-               if "--ask" in myopts and userquery(prompt, enter_invalid) == "No":
+               if prompt is not None and "--ask" in myopts and \
+                       userquery(prompt, enter_invalid) == "No":
                        print()
                        print("Quitting.")
                        print()
                        return 128 + signal.SIGINT
                # Don't ask again (e.g. when auto-cleaning packages after merge)
-               myopts.pop("--ask", None)
+               if mergecount != 0:
+                       myopts.pop("--ask", None)
 
        if ("--pretend" in myopts) and not ("--fetchonly" in myopts or "--fetch-all-uri" in myopts):
                if ("--resume" in myopts):
@@ -462,25 +465,29 @@ def action_build(settings, trees, mtimedb,
 
                        mydepgraph.saveNomergeFavorites()
 
-               mergetask = Scheduler(settings, trees, mtimedb, myopts,
-                       spinner, favorites=favorites,
-                       graph_config=mydepgraph.schedulerGraph())
-
-               del mydepgraph
-               clear_caches(trees)
-
-               retval = mergetask.merge()
-
-               if retval == os.EX_OK and not (buildpkgonly or fetchonly or pretend):
-                       if "yes" == settings.get("AUTOCLEAN"):
-                               portage.writemsg_stdout(">>> Auto-cleaning packages...\n")
-                               unmerge(trees[settings['EROOT']]['root_config'],
-                                       myopts, "clean", [],
-                                       ldpath_mtimes, autoclean=1)
-                       else:
-                               portage.writemsg_stdout(colorize("WARN", "WARNING:")
-                                       + " AUTOCLEAN is disabled.  This can cause serious"
-                                       + " problems due to overlapping packages.\n")
+               if mergecount == 0:
+                       retval = os.EX_OK
+               else:
+                       mergetask = Scheduler(settings, trees, mtimedb, myopts,
+                               spinner, favorites=favorites,
+                               graph_config=mydepgraph.schedulerGraph())
+
+                       del mydepgraph
+                       clear_caches(trees)
+
+                       retval = mergetask.merge()
+
+                       if retval == os.EX_OK and \
+                               not (buildpkgonly or fetchonly or pretend):
+                               if "yes" == settings.get("AUTOCLEAN"):
+                                       portage.writemsg_stdout(">>> Auto-cleaning packages...\n")
+                                       unmerge(trees[settings['EROOT']]['root_config'],
+                                               myopts, "clean", [],
+                                               ldpath_mtimes, autoclean=1)
+                               else:
+                                       portage.writemsg_stdout(colorize("WARN", "WARNING:")
+                                               + " AUTOCLEAN is disabled.  This can cause serious"
+                                               + " problems due to overlapping packages.\n")
 
                return retval
 
index 73ee3e9828e990fdcdbe60ba046c7bdcf12b8c91..3f242679cc1889936da3670f5da2fe84ca016617 100644 (file)
@@ -6879,16 +6879,31 @@ class depgraph(object):
                        all_added.append(SETPREFIX + k)
                all_added.extend(added_favorites)
                all_added.sort()
-               for a in all_added:
-                       if a.startswith(SETPREFIX):
-                               filename = "world_sets"
-                       else:
-                               filename = "world"
-                       writemsg_stdout(
-                               ">>> Recording %s in \"%s\" favorites file...\n" %
-                               (colorize("INFORM", _unicode(a)), filename), noiselevel=-1)
                if all_added:
-                       world_set.update(all_added)
+                       skip = False
+                       if "--ask" in self._frozen_config.myopts:
+                               writemsg_stdout("\n", noiselevel=-1)
+                               for a in all_added:
+                                       writemsg_stdout(" %s %s\n" % (colorize("GOOD", "*"), a),
+                                               noiselevel=-1)
+                               writemsg_stdout("\n", noiselevel=-1)
+                               prompt = "Would you like to add these packages to your world " \
+                                       "favorites?"
+                               enter_invalid = '--ask-enter-invalid' in \
+                                       self._frozen_config.myopts
+                               if userquery(prompt, enter_invalid) == "No":
+                                       skip = True
+
+                       if not skip:
+                               for a in all_added:
+                                       if a.startswith(SETPREFIX):
+                                               filename = "world_sets"
+                                       else:
+                                               filename = "world"
+                                       writemsg_stdout(
+                                               ">>> Recording %s in \"%s\" favorites file...\n" %
+                                               (colorize("INFORM", _unicode(a)), filename), noiselevel=-1)
+                               world_set.update(all_added)
 
                if world_locked:
                        world_set.unlock()