emerge --info: search similar names, bug #444596
authorZac Medico <zmedico@gentoo.org>
Sat, 24 Nov 2012 22:08:23 +0000 (14:08 -0800)
committerZac Medico <zmedico@gentoo.org>
Sat, 24 Nov 2012 22:08:23 +0000 (14:08 -0800)
pym/_emerge/actions.py

index b1feba65df5bd1b4a2915f70783d597b737f5417..cd52ddb1b25f727a93abc6b66d6e6e7ef7439674 100644 (file)
@@ -22,6 +22,7 @@ from itertools import chain
 
 import portage
 portage.proxy.lazyimport.lazyimport(globals(),
+       'portage.dbapi._similar_name_search:similar_name_search',
        'portage.debug',
        'portage.news:count_unread_news,display_news_notifications',
        '_emerge.chk_updated_cfg_files:chk_updated_cfg_files',
@@ -1366,6 +1367,7 @@ def action_info(settings, trees, myopts, myfiles):
        bindb = trees[eroot]["bintree"].dbapi
        for x in myfiles:
                match_found = False
+               cp_exists = False
                installed_match = vardb.match(x)
                for installed in installed_match:
                        mypkgs.append((installed, "installed"))
@@ -1378,6 +1380,9 @@ def action_info(settings, trees, myopts, myfiles):
                        if pkg_type == "binary" and "--usepkg" not in myopts:
                                continue
 
+                       if not cp_exists and db.cp_list(x.cp):
+                               cp_exists = True
+
                        matches = db.match(x)
                        matches.reverse()
                        for match in matches:
@@ -1400,8 +1405,34 @@ def action_info(settings, trees, myopts, myfiles):
                                xinfo = "%s for %s" % (xinfo, eroot)
                        writemsg("\nemerge: there are no ebuilds to satisfy %s.\n" %
                                colorize("INFORM", xinfo), noiselevel=-1)
-                       # TODO: Split out --misspell-suggestions code from depgraph
-                       # and call it here.
+
+                       if not cp_exists and myopts.get(
+                               "--misspell-suggestions", "y") != "n":
+
+                               writemsg("\nemerge: searching for similar names..."
+                                       , noiselevel=-1)
+
+                               dbs = [vardb]
+                               #if "--usepkgonly" not in myopts:
+                               dbs.append(portdb)
+                               if "--usepkg" in myopts:
+                                       dbs.append(bindb)
+
+                               matches = similar_name_search(dbs, x)
+
+                               if len(matches) == 1:
+                                       writemsg("\nemerge: Maybe you meant " + matches[0] + "?\n"
+                                               , noiselevel=-1)
+                               elif len(matches) > 1:
+                                       writemsg(
+                                               "\nemerge: Maybe you meant any of these: %s?\n" % \
+                                               (", ".join(matches),), noiselevel=-1)
+                               else:
+                                       # Generally, this would only happen if
+                                       # all dbapis are empty.
+                                       writemsg(" nothing similar found.\n"
+                                               , noiselevel=-1)
+
                        return 1
 
        output_buffer = []