Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/_emerge/
Date: Sat, 24 Nov 2012 21:57:23
Message-Id: 1353794211.abd18694835b9f8a5a515f9c6333a754703a0462.zmedico@gentoo
1 commit: abd18694835b9f8a5a515f9c6333a754703a0462
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sat Nov 24 21:56:51 2012 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sat Nov 24 21:56:51 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=abd18694
7
8 depgraph: split out similar_name_search func
9
10 This will allow the code to be re-used for bug #444596. Copyright
11 begins in 2011 since that's when the code for this feature was first
12 added in commit aa78cc8da18015b7d1e4eec277b5a7f940fe357c.
13
14 ---
15 pym/_emerge/depgraph.py | 50 +++-----------------------
16 pym/portage/dbapi/_similar_name_search.py | 57 +++++++++++++++++++++++++++++
17 2 files changed, 62 insertions(+), 45 deletions(-)
18
19 diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py
20 index c97aa02..365fbf8 100644
21 --- a/pym/_emerge/depgraph.py
22 +++ b/pym/_emerge/depgraph.py
23 @@ -3,7 +3,6 @@
24
25 from __future__ import print_function
26
27 -import difflib
28 import errno
29 import io
30 import logging
31 @@ -19,6 +18,7 @@ from portage import _unicode_decode, _unicode_encode, _encodings
32 from portage.const import PORTAGE_PACKAGE_ATOM, USER_CONFIG_PATH
33 from portage.dbapi import dbapi
34 from portage.dbapi.dep_expand import dep_expand
35 +from portage.dbapi._similar_name_search import similar_name_search
36 from portage.dep import Atom, best_match_to_list, extract_affecting_use, \
37 check_required_use, human_readable_required_use, match_from_list, \
38 _repo_separator
39 @@ -3678,57 +3678,17 @@ class depgraph(object):
40 not cp_exists and \
41 self._frozen_config.myopts.get(
42 "--misspell-suggestions", "y") != "n":
43 - cp = myparent.atom.cp.lower()
44 - cat, pkg = portage.catsplit(cp)
45 - if cat == "null":
46 - cat = None
47
48 writemsg("\nemerge: searching for similar names..."
49 , noiselevel=-1)
50
51 - all_cp = set()
52 - all_cp.update(vardb.cp_all())
53 + dbs = [vardb]
54 if "--usepkgonly" not in self._frozen_config.myopts:
55 - all_cp.update(portdb.cp_all())
56 + dbs.append(portdb)
57 if "--usepkg" in self._frozen_config.myopts:
58 - all_cp.update(bindb.cp_all())
59 - # discard dir containing no ebuilds
60 - all_cp.discard(cp)
61 + dbs.append(bindb)
62
63 - orig_cp_map = {}
64 - for cp_orig in all_cp:
65 - orig_cp_map.setdefault(cp_orig.lower(), []).append(cp_orig)
66 - all_cp = set(orig_cp_map)
67 -
68 - if cat:
69 - matches = difflib.get_close_matches(cp, all_cp)
70 - else:
71 - pkg_to_cp = {}
72 - for other_cp in list(all_cp):
73 - other_pkg = portage.catsplit(other_cp)[1]
74 - if other_pkg == pkg:
75 - # Check for non-identical package that
76 - # differs only by upper/lower case.
77 - identical = True
78 - for cp_orig in orig_cp_map[other_cp]:
79 - if portage.catsplit(cp_orig)[1] != \
80 - portage.catsplit(atom.cp)[1]:
81 - identical = False
82 - break
83 - if identical:
84 - # discard dir containing no ebuilds
85 - all_cp.discard(other_cp)
86 - continue
87 - pkg_to_cp.setdefault(other_pkg, set()).add(other_cp)
88 - pkg_matches = difflib.get_close_matches(pkg, pkg_to_cp)
89 - matches = []
90 - for pkg_match in pkg_matches:
91 - matches.extend(pkg_to_cp[pkg_match])
92 -
93 - matches_orig_case = []
94 - for cp in matches:
95 - matches_orig_case.extend(orig_cp_map[cp])
96 - matches = matches_orig_case
97 + matches = similar_name_search(dbs, atom)
98
99 if len(matches) == 1:
100 writemsg("\nemerge: Maybe you meant " + matches[0] + "?\n"
101
102 diff --git a/pym/portage/dbapi/_similar_name_search.py b/pym/portage/dbapi/_similar_name_search.py
103 new file mode 100644
104 index 0000000..d569fbf
105 --- /dev/null
106 +++ b/pym/portage/dbapi/_similar_name_search.py
107 @@ -0,0 +1,57 @@
108 +# Copyright 2011-2012 Gentoo Foundation
109 +# Distributed under the terms of the GNU General Public License v2
110 +
111 +import difflib
112 +
113 +from portage.versions import catsplit
114 +
115 +def similar_name_search(dbs, atom):
116 +
117 + cp = atom.cp.lower()
118 + cat, pkg = catsplit(cp)
119 + if cat == "null":
120 + cat = None
121 +
122 + all_cp = set()
123 + for db in dbs:
124 + all_cp.update(db.cp_all())
125 +
126 + # discard dir containing no ebuilds
127 + all_cp.discard(cp)
128 +
129 + orig_cp_map = {}
130 + for cp_orig in all_cp:
131 + orig_cp_map.setdefault(cp_orig.lower(), []).append(cp_orig)
132 + all_cp = set(orig_cp_map)
133 +
134 + if cat:
135 + matches = difflib.get_close_matches(cp, all_cp)
136 + else:
137 + pkg_to_cp = {}
138 + for other_cp in list(all_cp):
139 + other_pkg = catsplit(other_cp)[1]
140 + if other_pkg == pkg:
141 + # Check for non-identical package that
142 + # differs only by upper/lower case.
143 + identical = True
144 + for cp_orig in orig_cp_map[other_cp]:
145 + if catsplit(cp_orig)[1] != \
146 + catsplit(atom.cp)[1]:
147 + identical = False
148 + break
149 + if identical:
150 + # discard dir containing no ebuilds
151 + all_cp.discard(other_cp)
152 + continue
153 + pkg_to_cp.setdefault(other_pkg, set()).add(other_cp)
154 +
155 + pkg_matches = difflib.get_close_matches(pkg, pkg_to_cp)
156 + matches = []
157 + for pkg_match in pkg_matches:
158 + matches.extend(pkg_to_cp[pkg_match])
159 +
160 + matches_orig_case = []
161 + for cp in matches:
162 + matches_orig_case.extend(orig_cp_map[cp])
163 +
164 + return matches_orig_case