Gentoo Archives: gentoo-commits

From: Thomas Sachau <tommy@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:multilib commit in: pym/portage/package/ebuild/_config/
Date: Sun, 06 Feb 2011 13:17:22
Message-Id: 757d61c4041b11b124ee8baf9c2d482e15c89cb9.tommy@gentoo
1 commit: 757d61c4041b11b124ee8baf9c2d482e15c89cb9
2 Author: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
3 AuthorDate: Sun Jan 30 20:39:39 2011 +0000
4 Commit: Thomas Sachau <tommy <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 30 22:37:48 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=757d61c4
7
8 split up the getMissingKeywords code to eliminate code duplication and increase flexibility. Do some pyflakes and pylint cleanup
9
10 ---
11 .../package/ebuild/_config/KeywordsManager.py | 224 +++++++++++--------
12 1 files changed, 130 insertions(+), 94 deletions(-)
13
14 diff --git a/pym/portage/package/ebuild/_config/KeywordsManager.py b/pym/portage/package/ebuild/_config/KeywordsManager.py
15 index bff7afa..8a6b4bd 100644
16 --- a/pym/portage/package/ebuild/_config/KeywordsManager.py
17 +++ b/pym/portage/package/ebuild/_config/KeywordsManager.py
18 @@ -13,11 +13,14 @@ from portage.util import grabdict_package, stack_lists, writemsg
19 from portage.versions import cpv_getkey
20
21 class KeywordsManager(object):
22 + """Manager class to handle keywords processing and validation"""
23
24 - def __init__(self, profiles, abs_user_config, user_config=True, global_accept_keywords=""):
25 + def __init__(self, profiles, abs_user_config, user_config=True,
26 + global_accept_keywords=""):
27 self._pkeywords_list = []
28 rawpkeywords = [grabdict_package(
29 - os.path.join(x, "package.keywords"), recursive=1, verify_eapi=True) \
30 + os.path.join(x, "package.keywords"), recursive=1,
31 + verify_eapi=True) \
32 for x in profiles]
33 for pkeyworddict in rawpkeywords:
34 if not pkeyworddict:
35 @@ -31,7 +34,8 @@ class KeywordsManager(object):
36
37 self._p_accept_keywords = []
38 raw_p_accept_keywords = [grabdict_package(
39 - os.path.join(x, "package.accept_keywords"), recursive=1, verify_eapi=True) \
40 + os.path.join(x, "package.accept_keywords"), recursive=1,
41 + verify_eapi=True) \
42 for x in profiles]
43 for d in raw_p_accept_keywords:
44 if not d:
45 @@ -48,11 +52,13 @@ class KeywordsManager(object):
46 if user_config:
47 pkgdict = grabdict_package(
48 os.path.join(abs_user_config, "package.keywords"),
49 - recursive=1, allow_wildcard=True, allow_repo=True, verify_eapi=False)
50 + recursive=1, allow_wildcard=True, allow_repo=True,
51 + verify_eapi=False)
52
53 for k, v in grabdict_package(
54 os.path.join(abs_user_config, "package.accept_keywords"),
55 - recursive=1, allow_wildcard=True, allow_repo=True, verify_eapi=False).items():
56 + recursive=1, allow_wildcard=True, allow_repo=True,
57 + verify_eapi=False).items():
58 pkgdict.setdefault(k, []).extend(v)
59
60 accept_keywords_defaults = global_accept_keywords.split()
61 @@ -66,6 +72,7 @@ class KeywordsManager(object):
62 v = tuple(v)
63 self.pkeywordsdict.setdefault(k.cp, {})[k] = v
64
65 +
66 def getKeywords(self, cpv, slot, keywords, repo):
67 cp = cpv_getkey(cpv)
68 pkg = "".join((cpv, _slot_separator, slot))
69 @@ -80,7 +87,14 @@ class KeywordsManager(object):
70 keywords.extend(pkg_keywords)
71 return stack_lists(keywords, incremental=True)
72
73 - def getMissingKeywords(self, cpv, slot, keywords, repo, global_accept_keywords, backuped_accept_keywords):
74 +
75 + def getMissingKeywords(self,
76 + cpv,
77 + slot,
78 + keywords,
79 + repo,
80 + global_accept_keywords,
81 + backuped_accept_keywords):
82 """
83 Take a package and return a list of any KEYWORDS that the user may
84 need to accept for the given package. If the KEYWORDS are empty
85 @@ -102,88 +116,30 @@ class KeywordsManager(object):
86 @return: A list of KEYWORDS that have not been accepted.
87 """
88
89 - # Hack: Need to check the env directly here as otherwise stacking
90 - # doesn't work properly as negative values are lost in the config
91 - # object (bug #139600)
92 - egroups = backuped_accept_keywords.split()
93 mygroups = self.getKeywords(cpv, slot, keywords, repo)
94 # Repoman may modify this attribute as necessary.
95 pgroups = global_accept_keywords.split()
96 - matches = False
97 - cp = cpv_getkey(cpv)
98
99 - if self._p_accept_keywords:
100 - cpv_slot = "%s:%s" % (cpv, slot)
101 - accept_keywords_defaults = tuple('~' + keyword for keyword in \
102 - pgroups if keyword[:1] not in "~-")
103 - for d in self._p_accept_keywords:
104 - cpdict = d.get(cp)
105 - if cpdict:
106 - pkg_accept_keywords = \
107 - ordered_by_atom_specificity(cpdict, cpv_slot)
108 - if pkg_accept_keywords:
109 - for x in pkg_accept_keywords:
110 - if not x:
111 - x = accept_keywords_defaults
112 - pgroups.extend(x)
113 - matches = True
114 + unmaskgroups = self.getPKeywords(cpv, slot, repo,
115 + global_accept_keywords)
116 + pgroups.extend(unmaskgroups)
117
118 - pkgdict = self.pkeywordsdict.get(cp)
119 - if pkgdict:
120 - cpv_slot = "%s:%s" % (cpv, slot)
121 - pkg_accept_keywords = \
122 - ordered_by_atom_specificity(pkgdict, cpv_slot, repo=repo)
123 - if pkg_accept_keywords:
124 - for x in pkg_accept_keywords:
125 - pgroups.extend(x)
126 - matches = True
127 + # Hack: Need to check the env directly here as otherwise stacking
128 + # doesn't work properly as negative values are lost in the config
129 + # object (bug #139600)
130 + egroups = self._getEgroups(backuped_accept_keywords)
131 + pgroups.extend(egroups)
132
133 - if matches or egroups:
134 - pgroups.extend(egroups)
135 - inc_pgroups = set()
136 - for x in pgroups:
137 - if x.startswith("-"):
138 - if x == "-*":
139 - inc_pgroups.clear()
140 - else:
141 - inc_pgroups.discard(x[1:])
142 - else:
143 - inc_pgroups.add(x)
144 - pgroups = inc_pgroups
145 - del inc_pgroups
146 + return self._getMissingKeywords(cpv, pgroups, mygroups)
147
148 - match = False
149 - hasstable = False
150 - hastesting = False
151 - for gp in mygroups:
152 - if gp == "*" or (gp == "-*" and len(mygroups) == 1):
153 - writemsg(_("--- WARNING: Package '%(cpv)s' uses"
154 - " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, noiselevel=-1)
155 - if gp == "*":
156 - match = 1
157 - break
158 - elif gp in pgroups:
159 - match=1
160 - break
161 - elif gp.startswith("~"):
162 - hastesting = True
163 - elif not gp.startswith("-"):
164 - hasstable = True
165 - if not match and \
166 - ((hastesting and "~*" in pgroups) or \
167 - (hasstable and "*" in pgroups) or "**" in pgroups):
168 - match=1
169 - if match:
170 - missing = []
171 - else:
172 - if not mygroups:
173 - # If KEYWORDS is empty then we still have to return something
174 - # in order to distinguish from the case of "none missing".
175 - mygroups.append("**")
176 - missing = mygroups
177 - return missing
178
179 - def getRawMissingKeywords(self, cpv, slot, keywords, repo, global_accept_keywords, backuped_accept_keywords):
180 + def getRawMissingKeywords(self,
181 + cpv,
182 + slot,
183 + keywords,
184 + repo,
185 + global_accept_keywords,
186 + backuped_accept_keywords):
187 """
188 Take a package and return a list of any KEYWORDS that the user may
189 need to accept for the given package. If the KEYWORDS are empty,
190 @@ -206,18 +162,37 @@ class KeywordsManager(object):
191 and the keywords it looked for.
192 """
193
194 - # Hack: Need to check the env directly here as otherwise stacking
195 - # doesn't work properly as negative values are lost in the config
196 - # object (bug #139600)
197 - egroups = backuped_accept_keywords.split()
198 mygroups = self.getKeywords(cpv, slot, keywords, repo)
199 # Repoman may modify this attribute as necessary.
200 pgroups = global_accept_keywords.split()
201 - matches = False
202
203 - ## we want to use the environment keywords here,
204 - ## but stripped to it's base arch
205 - ## we want the raw keywords needed to be accepted from the ebuild
206 + # Hack: Need to check the env directly here as otherwise stacking
207 + # doesn't work properly as negative values are lost in the config
208 + # object (bug #139600)
209 + # we want to use the environment keywords here,
210 + # but stripped to it's base arch
211 + # we want the raw keywords needed to be accepted from the ebuild
212 + egroups = self._getEgroups(backuped_accept_keywords)
213 + egroups = [x.lstrip('~') for x in egroups]
214 +
215 + pgroups.extend(egroups)
216 +
217 + missing = self._getMissingKeywords(cpv, pgroups, mygroups)
218 +
219 + return missing, pgroups
220 +
221 +
222 + @staticmethod
223 + def _getEgroups(backuped_accept_keywords):
224 + """gets any keywords defined in the environment
225 +
226 + @param backuped_accept_keywords: ACCEPT_KEYWORDS from the backup env
227 + @type backuped_accept_keywords: String
228 + @rtype: List
229 + @return: list of KEYWORDS that have been accepted
230 + """
231 + egroups = backuped_accept_keywords.split()
232 + pgroups = []
233 if egroups:
234 pgroups.extend(egroups)
235 inc_pgroups = set()
236 @@ -228,22 +203,34 @@ class KeywordsManager(object):
237 else:
238 inc_pgroups.discard(x[1:])
239 else:
240 - inc_pgroups.add(x.lstrip('~'))
241 + inc_pgroups.add(x)
242 pgroups = inc_pgroups
243 del inc_pgroups
244 + return pgroups
245 +
246
247 + @staticmethod
248 + def _getMissingKeywords(cpv, pgroups, mygroups):
249 + """Determines the missing keywords
250 +
251 + @param pgroups: The pkg keywords accepted
252 + @type pgroups: list
253 + @param mygroups: The ebuild keywords
254 + @type mygroups: list
255 + """
256 match = False
257 hasstable = False
258 hastesting = False
259 for gp in mygroups:
260 if gp == "*" or (gp == "-*" and len(mygroups) == 1):
261 writemsg(_("--- WARNING: Package '%(cpv)s' uses"
262 - " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp}, noiselevel=-1)
263 + " '%(keyword)s' keyword.\n") % {"cpv": cpv, "keyword": gp},
264 + noiselevel=-1)
265 if gp == "*":
266 - match = 1
267 + match = True
268 break
269 elif gp in pgroups:
270 - match=1
271 + match = True
272 break
273 elif gp.startswith("~"):
274 hastesting = True
275 @@ -252,7 +239,7 @@ class KeywordsManager(object):
276 if not match and \
277 ((hastesting and "~*" in pgroups) or \
278 (hasstable and "*" in pgroups) or "**" in pgroups):
279 - match=1
280 + match = True
281 if match:
282 missing = []
283 else:
284 @@ -261,4 +248,53 @@ class KeywordsManager(object):
285 # in order to distinguish from the case of "none missing".
286 mygroups.append("**")
287 missing = mygroups
288 - return missing, pgroups
289 + return missing
290 +
291 +
292 + def getPKeywords(self, cpv, slot, repo, global_accept_keywords):
293 + """Gets any package.keywords settings for cp for the given
294 + cpv, slot and repo
295 +
296 + @param cpv: The package name (for package.keywords support)
297 + @type cpv: String
298 + @param slot: The 'SLOT' key from the raw package metadata
299 + @type slot: String
300 + @param keywords: The 'KEYWORDS' key from the raw package metadata
301 + @type keywords: String
302 + @param global_accept_keywords: The current value of ACCEPT_KEYWORDS
303 + @type global_accept_keywords: String
304 + @param backuped_accept_keywords: ACCEPT_KEYWORDS from the backup env
305 + @type backuped_accept_keywords: String
306 + @rtype: List
307 + @return: list of KEYWORDS that have been accepted
308 + """
309 +
310 + pgroups = global_accept_keywords.split()
311 + cp = cpv_getkey(cpv)
312 +
313 + unmaskgroups = []
314 + if self._p_accept_keywords:
315 + cpv_slot = "%s:%s" % (cpv, slot)
316 + accept_keywords_defaults = tuple('~' + keyword for keyword in \
317 + pgroups if keyword[:1] not in "~-")
318 + for d in self._p_accept_keywords:
319 + cpdict = d.get(cp)
320 + if cpdict:
321 + pkg_accept_keywords = \
322 + ordered_by_atom_specificity(cpdict, cpv_slot)
323 + if pkg_accept_keywords:
324 + for x in pkg_accept_keywords:
325 + if not x:
326 + x = accept_keywords_defaults
327 + unmaskgroups.extend(x)
328 +
329 + pkgdict = self.pkeywordsdict.get(cp)
330 + if pkgdict:
331 + cpv_slot = "%s:%s" % (cpv, slot)
332 + pkg_accept_keywords = \
333 + ordered_by_atom_specificity(pkgdict, cpv_slot, repo=repo)
334 + if pkg_accept_keywords:
335 + for x in pkg_accept_keywords:
336 + unmaskgroups.extend(x)
337 + return unmaskgroups
338 +