When given an ambiguous ebuild name to install, format the list of choices
authorZac Medico <zmedico@gentoo.org>
Fri, 21 Nov 2008 02:46:56 +0000 (02:46 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 21 Nov 2008 02:46:56 +0000 (02:46 -0000)
in emerge --search format if --quiet mode is not enabled, otherwise just show
a brief list. Thanks to Markus Meier <maekke@g.o> for the suggestion.

svn path=/main/trunk/; revision=12012

pym/_emerge/__init__.py

index f3f704754d2437ed9d5f572ec6e5259976a4a904..4a78b54f19ceed94c2d6735104cffc28c187167e 100644 (file)
@@ -426,6 +426,8 @@ class search(object):
                self.searchdesc = searchdesc
                self.root_config = root_config
                self.setconfig = root_config.setconfig
+               self.matches = {"pkg" : []}
+               self.mlen = 0
 
                def fake_portdb():
                        pass
@@ -542,7 +544,7 @@ class search(object):
                                        if not result or cpv == portage.best([cpv, result]):
                                                result = cpv
                                else:
-                                       db_keys = list(db._aux_cache_keys)
+                                       db_keys = Package.metadata_keys
                                        # break out of this loop with highest visible
                                        # match, checked in descending order
                                        for cpv in reversed(db.match(atom)):
@@ -635,6 +637,15 @@ class search(object):
                        self.matches[mtype].sort()
                        self.mlen += len(self.matches[mtype])
 
+       def addCP(self, cp):
+               if not self.portdb.xmatch("match-all", cp):
+                       return
+               masked = 0
+               if not self.portdb.xmatch("bestmatch-visible", cp):
+                       masked = 1
+               self.matches["pkg"].append([cp, masked])
+               self.mlen += 1
+
        def output(self):
                """Outputs the results of the search."""
                print "\b\b  \n[ Results for search key : "+white(self.searchkey)+" ]"
@@ -729,7 +740,6 @@ class search(object):
                                                print "     ", darkgreen("Description:")+"  ",desc
                                                print "     ", darkgreen("License:")+"      ",license
                                                print
-               print
        #
        # private interface
        #
@@ -5023,13 +5033,10 @@ class depgraph(object):
                                                if portage.dep_getkey(atom) == installed_cp]
 
                                if len(expanded_atoms) > 1:
-                                       print "\n\n!!! The short ebuild name \"" + x + "\" is ambiguous.  Please specify"
-                                       print "!!! one of the following fully-qualified ebuild names instead:\n"
-                                       expanded_atoms = set(portage.dep_getkey(atom) \
-                                               for atom in expanded_atoms)
-                                       for i in sorted(expanded_atoms):
-                                               print "    " + green(i)
                                        print
+                                       print
+                                       ambiguous_package_name(x, expanded_atoms, root_config,
+                                               self.spinner, self.myopts)
                                        return False, myfavorites
                                if expanded_atoms:
                                        atom = expanded_atoms[0]
@@ -13871,6 +13878,28 @@ def repo_name_check(trees):
 
        return bool(missing_repo_names)
 
+def ambiguous_package_name(arg, atoms, root_config, spinner, myopts):
+
+       if "--quiet" in myopts:
+               print "!!! The short ebuild name \"%s\" is ambiguous. Please specify" % arg
+               print "!!! one of the following fully-qualified ebuild names instead:\n"
+               for cp in sorted(set(portage.dep_getkey(atom) for atom in atoms)):
+                       print "    " + colorize("INFORM", cp)
+               return
+
+       s = search(root_config, spinner, "--searchdesc" in myopts,
+               "--quiet" not in myopts, "--usepkg" in myopts,
+               "--usepkgonly" in myopts)
+       null_cp = portage.dep_getkey(insert_category_into_atom(
+               arg, "null"))
+       cat, atom_pn = portage.catsplit(null_cp)
+       s.searchkey = atom_pn
+       for cp in sorted(set(portage.dep_getkey(atom) for atom in atoms)):
+               s.addCP(cp)
+       s.output()
+       print "!!! The short ebuild name \"%s\" is ambiguous. Please specify" % arg
+       print "!!! one of the above fully-qualified ebuild names instead.\n"
+
 def emerge_main():
        global portage  # NFC why this is necessary now - genone
        portage._disable_legacy_globals()