1 |
Author: zmedico |
2 |
Date: 2008-05-25 21:34:21 +0000 (Sun, 25 May 2008) |
3 |
New Revision: 10419 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/_emerge/__init__.py |
7 |
main/trunk/pym/portage/dep.py |
8 |
main/trunk/pym/portage/sets/base.py |
9 |
Log: |
10 |
* Add support for Package instances and USE deps in match_from_list(). |
11 |
* Add USE dep matching support to depgraph._iter_atoms_for_pkg(). |
12 |
|
13 |
|
14 |
Modified: main/trunk/pym/_emerge/__init__.py |
15 |
=================================================================== |
16 |
--- main/trunk/pym/_emerge/__init__.py 2008-05-25 17:54:21 UTC (rev 10418) |
17 |
+++ main/trunk/pym/_emerge/__init__.py 2008-05-25 21:34:21 UTC (rev 10419) |
18 |
@@ -1268,7 +1268,8 @@ |
19 |
__slots__ = ("built", "cpv", "depth", |
20 |
"installed", "metadata", "onlydeps", "operation", |
21 |
"root", "type_name", |
22 |
- "category", "cp", "cpv_slot", "pf", "pv_split", "slot_atom") |
23 |
+ "category", "cp", "cpv_slot", "cpv_split", |
24 |
+ "pf", "pv_split", "slot", "slot_atom", "use") |
25 |
|
26 |
metadata_keys = [ |
27 |
"CHOST", "COUNTER", "DEPEND", "EAPI", "IUSE", "KEYWORDS", |
28 |
@@ -1277,12 +1278,44 @@ |
29 |
|
30 |
def __init__(self, **kwargs): |
31 |
Task.__init__(self, **kwargs) |
32 |
+ self.metadata = self._metadata_wrapper(self, self.metadata) |
33 |
self.cp = portage.cpv_getkey(self.cpv) |
34 |
- self.slot_atom = "%s:%s" % (self.cp, self.metadata["SLOT"]) |
35 |
- self.cpv_slot = "%s:%s" % (self.cpv, self.metadata["SLOT"]) |
36 |
+ self.slot = self.metadata["SLOT"] |
37 |
+ self.slot_atom = portage.dep.Atom("%s:%s" % \ |
38 |
+ (self.cp, self.metadata["SLOT"])) |
39 |
+ |
40 |
+ # This used to be "%s:%s" % (self.cpv, self.slot) but now |
41 |
+ # is's just a reference to self since match_from_list() |
42 |
+ # now supports Package references. |
43 |
+ self.cpv_slot = self |
44 |
+ |
45 |
self.category, self.pf = portage.catsplit(self.cpv) |
46 |
- self.pv_split = portage.catpkgsplit(self.cpv)[1:] |
47 |
+ self.cpv_split = portage.catpkgsplit(self.cpv) |
48 |
+ self.pv_split = self.cpv_split[1:] |
49 |
+ self.use = self._use(self.metadata["USE"].split()) |
50 |
|
51 |
+ class _use(object): |
52 |
+ def __init__(self, use): |
53 |
+ self.enabled = frozenset(use) |
54 |
+ |
55 |
+ class _metadata_wrapper(dict): |
56 |
+ """ |
57 |
+ Detect metadata updates and synchronize Package attributes. |
58 |
+ """ |
59 |
+ def __init__(self, pkg, metadata): |
60 |
+ dict.__init__(self, metadata.iteritems()) |
61 |
+ self._pkg = pkg |
62 |
+ |
63 |
+ def __setitem__(self, k, v): |
64 |
+ dict.__setitem__(self, k, v) |
65 |
+ if k == "USE": |
66 |
+ self._pkg.use = self._pkg._use(v.split()) |
67 |
+ |
68 |
+ def _metadata_setitem(self, k, v): |
69 |
+ self._metadata_setitem_orig(k, v) |
70 |
+ if k == "USE": |
71 |
+ self.use = self._use(self) |
72 |
+ |
73 |
def _get_hash_key(self): |
74 |
hash_key = getattr(self, "_hash_key", None) |
75 |
if hash_key is None: |
76 |
@@ -3035,18 +3068,7 @@ |
77 |
installed=installed, metadata=metadata, |
78 |
onlydeps=onlydeps, root=root, type_name=pkg_type) |
79 |
self._pkg_cache[pkg] = pkg |
80 |
- myarg = None |
81 |
- if root == self.target_root: |
82 |
- try: |
83 |
- myarg = self._iter_atoms_for_pkg(pkg).next() |
84 |
- except StopIteration: |
85 |
- pass |
86 |
- except portage.exception.InvalidDependString: |
87 |
- if not installed: |
88 |
- # masked by corruption |
89 |
- continue |
90 |
- if not installed and myarg: |
91 |
- found_available_arg = True |
92 |
+ |
93 |
if not installed or (installed and matched_packages): |
94 |
# Only enforce visibility on installed packages |
95 |
# if there is at least one other visible package |
96 |
@@ -3085,6 +3107,22 @@ |
97 |
# it's expensive. |
98 |
pkgsettings.setcpv(cpv, mydb=pkg.metadata) |
99 |
pkg.metadata["USE"] = pkgsettings["PORTAGE_USE"] |
100 |
+ |
101 |
+ myarg = None |
102 |
+ if root == self.target_root: |
103 |
+ try: |
104 |
+ # Ebuild USE must have been calculated prior |
105 |
+ # to this point, in case atoms have USE deps. |
106 |
+ myarg = self._iter_atoms_for_pkg(pkg).next() |
107 |
+ except StopIteration: |
108 |
+ pass |
109 |
+ except portage.exception.InvalidDependString: |
110 |
+ if not installed: |
111 |
+ # masked by corruption |
112 |
+ continue |
113 |
+ if not installed and myarg: |
114 |
+ found_available_arg = True |
115 |
+ |
116 |
if atom.use and not pkg.built: |
117 |
use = pkg.metadata["USE"].split() |
118 |
if atom.use.enabled.difference(use): |
119 |
|
120 |
Modified: main/trunk/pym/portage/dep.py |
121 |
=================================================================== |
122 |
--- main/trunk/pym/portage/dep.py 2008-05-25 17:54:21 UTC (rev 10418) |
123 |
+++ main/trunk/pym/portage/dep.py 2008-05-25 21:34:21 UTC (rev 10419) |
124 |
@@ -759,6 +759,9 @@ |
125 |
@return: A list of package atoms that match the given package atom |
126 |
""" |
127 |
|
128 |
+ if not candidate_list: |
129 |
+ return [] |
130 |
+ |
131 |
from portage.util import writemsg |
132 |
if "!" == mydep[:1]: |
133 |
mydep = mydep[1:] |
134 |
@@ -791,13 +794,21 @@ |
135 |
|
136 |
if operator is None: |
137 |
for x in candidate_list: |
138 |
- if dep_getkey(x) != mycpv: |
139 |
+ cp = getattr(x, "cp", None) |
140 |
+ if cp is None: |
141 |
+ cp = dep_getkey(x) |
142 |
+ if cp != mycpv: |
143 |
continue |
144 |
mylist.append(x) |
145 |
|
146 |
elif operator == "=": # Exact match |
147 |
- mylist = [cpv for cpv in candidate_list if \ |
148 |
- cpvequal(remove_slot(cpv), mycpv)] |
149 |
+ for x in candidate_list: |
150 |
+ xcpv = getattr(x, "cpv", None) |
151 |
+ if xcpv is None: |
152 |
+ xcpv = dep_getcpv(x) |
153 |
+ if not cpvequal(xcpv, mycpv): |
154 |
+ continue |
155 |
+ mylist.append(x) |
156 |
|
157 |
elif operator == "=*": # glob match |
158 |
# XXX: Nasty special casing for leading zeros |
159 |
@@ -809,7 +820,9 @@ |
160 |
myver = "0"+myver |
161 |
mycpv = mysplit[0]+"/"+mysplit[1]+"-"+myver |
162 |
for x in candidate_list: |
163 |
- xs = catpkgsplit(remove_slot(x)) |
164 |
+ xs = getattr(x, "cpv_split", None) |
165 |
+ if xs is None: |
166 |
+ xs = catpkgsplit(remove_slot(x)) |
167 |
myver = xs[2].lstrip("0") |
168 |
if not myver or not myver[0].isdigit(): |
169 |
myver = "0"+myver |
170 |
@@ -819,8 +832,10 @@ |
171 |
|
172 |
elif operator == "~": # version, any revision, match |
173 |
for x in candidate_list: |
174 |
- xs = catpkgsplit(remove_slot(x)) |
175 |
+ xs = getattr(x, "cpv_split", None) |
176 |
if xs is None: |
177 |
+ xs = catpkgsplit(remove_slot(x)) |
178 |
+ if xs is None: |
179 |
raise InvalidData(x) |
180 |
if not cpvequal(xs[0]+"/"+xs[1]+"-"+xs[2], mycpv_cps[0]+"/"+mycpv_cps[1]+"-"+mycpv_cps[2]): |
181 |
continue |
182 |
@@ -831,8 +846,13 @@ |
183 |
elif operator in [">", ">=", "<", "<="]: |
184 |
mysplit = ["%s/%s" % (cat, pkg), ver, rev] |
185 |
for x in candidate_list: |
186 |
+ xs = getattr(x, "cpv_split", None) |
187 |
+ if xs is None: |
188 |
+ xs = catpkgsplit(remove_slot(x)) |
189 |
+ xcat, xpkg, xver, xrev = xs |
190 |
+ xs = ["%s/%s" % (xcat, xpkg), xver, xrev] |
191 |
try: |
192 |
- result = pkgcmp(pkgsplit(remove_slot(x)), mysplit) |
193 |
+ result = pkgcmp(xs, mysplit) |
194 |
except ValueError: # pkgcmp may return ValueError during int() conversion |
195 |
writemsg("\nInvalid package name: %s\n" % x, noiselevel=-1) |
196 |
raise |
197 |
@@ -859,9 +879,26 @@ |
198 |
candidate_list = mylist |
199 |
mylist = [] |
200 |
for x in candidate_list: |
201 |
- xslot = dep_getslot(x) |
202 |
+ xslot = getattr(x, "slot", None) |
203 |
+ if xslot is None and isinstance(x, basestring): |
204 |
+ xslot = dep_getslot(x) |
205 |
if xslot is not None and xslot != slot: |
206 |
continue |
207 |
mylist.append(x) |
208 |
|
209 |
+ if mydep.use: |
210 |
+ candidate_list = mylist |
211 |
+ mylist = [] |
212 |
+ for x in candidate_list: |
213 |
+ # Note: IUSE intersection is neglected here since there |
214 |
+ # is currently no way to access implicit IUSE. However, IUSE |
215 |
+ # filtering can be added elsewhere in the chain. |
216 |
+ use = getattr(x, "use", None) |
217 |
+ if use is not None: |
218 |
+ if mydep.use.enabled.difference(use.enabled): |
219 |
+ continue |
220 |
+ if mydep.use.disabled.intersection(use.enabled): |
221 |
+ continue |
222 |
+ mylist.append(x) |
223 |
+ |
224 |
return mylist |
225 |
|
226 |
Modified: main/trunk/pym/portage/sets/base.py |
227 |
=================================================================== |
228 |
--- main/trunk/pym/portage/sets/base.py 2008-05-25 17:54:21 UTC (rev 10418) |
229 |
+++ main/trunk/pym/portage/sets/base.py 2008-05-25 21:34:21 UTC (rev 10419) |
230 |
@@ -108,7 +108,7 @@ |
231 |
atoms = list(self.iterAtomsForPackage(pkg)) |
232 |
if not atoms: |
233 |
return None |
234 |
- return best_match_to_list(pkg.cpv_slot, atoms) |
235 |
+ return best_match_to_list(pkg, atoms) |
236 |
|
237 |
def iterAtomsForPackage(self, pkg): |
238 |
""" |
239 |
@@ -116,7 +116,7 @@ |
240 |
arguments against the PROVIDE metadata. This will raise an |
241 |
InvalidDependString exception if PROVIDE is invalid. |
242 |
""" |
243 |
- cpv_slot_list = ["%s:%s" % (pkg.cpv, pkg.metadata["SLOT"])] |
244 |
+ cpv_slot_list = [pkg] |
245 |
cp = cpv_getkey(pkg.cpv) |
246 |
self._load() # make sure the atoms are loaded |
247 |
atoms = self._atommap.get(cp) |
248 |
|
249 |
-- |
250 |
gentoo-commits@l.g.o mailing list |