From: Sebastian Luther Date: Mon, 31 Jan 2011 22:35:40 +0000 (+0100) Subject: Print near matches for cmd line atoms without matching ebuild X-Git-Tag: v2.1.9.36~42 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6203db15eb4da02bb96c6fbfc998784adc5b6c4d;p=portage.git Print near matches for cmd line atoms without matching ebuild --- diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 37615a1ee..0c56e35ef 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -3,6 +3,7 @@ from __future__ import print_function +import difflib import gc import logging import re @@ -2348,6 +2349,8 @@ class depgraph(object): pkgsettings = self._frozen_config.pkgsettings[root] root_config = self._frozen_config.roots[root] portdb = self._frozen_config.roots[root].trees["porttree"].dbapi + vardb = self._frozen_config.roots[root].trees["vartree"].dbapi + bindb = self._frozen_config.roots[root].trees["bintree"].dbapi dbs = self._dynamic_config._filtered_trees[root]["dbs"] for db, pkg_type, built, installed, db_keys in dbs: if installed: @@ -2614,6 +2617,36 @@ class depgraph(object): mask_docs = True else: writemsg_stdout("\nemerge: there are no ebuilds to satisfy "+green(xinfo)+".\n", noiselevel=-1) + if isinstance(myparent, AtomArg): + cp = myparent.atom.cp + cat, pkg = cp.split("/") + if cat == "null": + cat = None + + all_cp = set() + all_cp.update(vardb.cp_all()) + all_cp.update(portdb.cp_all()) + if "--usepkg" in self._frozen_config.myopts: + all_cp.update(bindb.cp_all()) + + if cat: + matches = difflib.get_close_matches(cp, all_cp) + else: + pkg_to_cp = {} + for other_cp in all_cp: + other_pkg = other_cp.split("/")[1] + pkg_to_cp.setdefault(other_pkg, set()).add(other_cp) + pkg_matches = difflib.get_close_matches(pkg, pkg_to_cp) + matches = [] + for pkg_match in pkg_matches: + matches.extend(pkg_to_cp[pkg_match]) + + if len(matches) == 1: + writemsg_stdout("emerge: Maybe you meant " + matches[0] + "?\n" + , noiselevel=-1) + elif len(matches) > 1: + writemsg_stdout("emerge: Maybe you meant any of these: " + ", ".join(matches) + "?\n" + , noiselevel=-1) msg = [] if not isinstance(myparent, AtomArg):