1 |
commit: d1f4f46de1234dbf750ab8815dcf2aa6a827eb4d |
2 |
Author: Gilles Dartiguelongue <eva <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 24 09:35:49 2015 +0000 |
4 |
Commit: Gilles Dartiguelongue <eva <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Jun 25 12:45:47 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gnome.git/commit/?id=d1f4f46d |
7 |
|
8 |
scripts/gen_archlist: apply PEP8 rules |
9 |
|
10 |
scripts/gen_archlist.py | 145 ++++++++++++++++++++++++++++++------------------ |
11 |
1 file changed, 90 insertions(+), 55 deletions(-) |
12 |
|
13 |
diff --git a/scripts/gen_archlist.py b/scripts/gen_archlist.py |
14 |
index fa26b90..407ebbd 100755 |
15 |
--- a/scripts/gen_archlist.py |
16 |
+++ b/scripts/gen_archlist.py |
17 |
@@ -10,10 +10,10 @@ |
18 |
# You can use test-data/package-list to test the script out. |
19 |
# |
20 |
# NOTE: This script assumes that there are no broken keyword deps |
21 |
-# |
22 |
+# |
23 |
# BUGS: |
24 |
-# * belongs_release() is a very primitive function, which means usage of old/new |
25 |
-# release numbers gives misleading output |
26 |
+# * belongs_release() is a very primitive function, which means usage of |
27 |
+# old/new release numbers gives misleading output |
28 |
# * Will show multiple versions of the same package in the output sometimes. |
29 |
# This happens when a cp is specified in the cpv list, and is resolved as |
30 |
# a dependency as well. |
31 |
@@ -22,25 +22,29 @@ |
32 |
# |
33 |
|
34 |
from __future__ import division |
35 |
-import os, sys |
36 |
+ |
37 |
+import os |
38 |
+import sys |
39 |
+ |
40 |
import portage |
41 |
|
42 |
-############### |
43 |
-## Constants ## |
44 |
-############### |
45 |
-#GNOME_OVERLAY = PORTDB.getRepositoryPath('gnome') |
46 |
+############# |
47 |
+# Constants # |
48 |
+############# |
49 |
+# GNOME_OVERLAY = PORTDB.getRepositoryPath('gnome') |
50 |
portage.portdb.porttrees = [portage.settings['PORTDIR']] |
51 |
STABLE_ARCHES = ('alpha', 'amd64', 'arm', 'hppa', 'ia64', 'm68k', 'ppc', |
52 |
- 'ppc64', 's390', 'sh', 'sparc', 'x86') |
53 |
-UNSTABLE_ARCHES = ('~alpha', '~amd64', '~arm', '~hppa', '~ia64', '~m68k', '~ppc', |
54 |
- '~ppc64', '~s390', '~sh', '~sparc', '~x86', '~x86-fbsd') |
55 |
-ALL_ARCHES = STABLE_ARCHES+UNSTABLE_ARCHES |
56 |
+ 'ppc64', 's390', 'sh', 'sparc', 'x86') |
57 |
+UNSTABLE_ARCHES = ('~alpha', '~amd64', '~arm', '~hppa', '~ia64', '~m68k', |
58 |
+ '~ppc', '~ppc64', '~s390', '~sh', '~sparc', '~x86', |
59 |
+ '~x86-fbsd') |
60 |
+ALL_ARCHES = STABLE_ARCHES + UNSTABLE_ARCHES |
61 |
SYSTEM_PACKAGES = [] |
62 |
LINE_SEP = '' |
63 |
|
64 |
-############## |
65 |
-## Settings ## |
66 |
-############## |
67 |
+############ |
68 |
+# Settings # |
69 |
+############ |
70 |
DEBUG = False |
71 |
EXTREME_DEBUG = False |
72 |
CHECK_DEPS = False |
73 |
@@ -48,40 +52,45 @@ APPEND_SLOTS = False |
74 |
# Check for stable keywords |
75 |
STABLE = True |
76 |
|
77 |
-################# |
78 |
-## Preparation ## |
79 |
-################# |
80 |
+############### |
81 |
+# Preparation # |
82 |
+############### |
83 |
ALL_CPV_KWS = [] |
84 |
OLD_REL = None |
85 |
NEW_REL = None |
86 |
+ |
87 |
if __name__ == "__main__": |
88 |
try: |
89 |
- CP_FILE = sys.argv[1] # File which has the cp list |
90 |
+ CP_FILE = sys.argv[1] # File which has the cp list |
91 |
except IndexError: |
92 |
- print 'Usage: %s <file> [old_rel] [new_rel]' % sys.argv[0] |
93 |
- print 'Where <file> is a file with a category/package list' |
94 |
- print ' [old_rel] is an optional argument for specifying which release cycle' |
95 |
- print ' to use to get the cpv which has the keyword we need' |
96 |
- print ' i.e., which cpvs will we get the list of keywords from?' |
97 |
- print ' [new_rel] is an optional argument for specifying which release cycle' |
98 |
- print ' to use to get the latest cpv on which we want keywords' |
99 |
- print ' i.e., which cpvs will go in the list?' |
100 |
- print 'WARNING: the logic for old_rel & new_rel is very incomplete. See TODO' |
101 |
+ print """Usage: %s <file> [old_rel] [new_rel] |
102 |
+ |
103 |
+Where <file> is a file with a category/package list |
104 |
+ [old_rel] is an optional argument for specifying which release cycle |
105 |
+ to use to get the cpv which has the keyword we need |
106 |
+ i.e., which cpvs will we get the list of keywords from? |
107 |
+ [new_rel] is an optional argument for specifying which release cycle |
108 |
+ to use to get the latest cpv on which we want keywords |
109 |
+ i.e., which cpvs will go in the list? |
110 |
+WARNING: the logic for old_rel & new_rel is very incomplete. See TODO |
111 |
+""" % sys.argv[0] |
112 |
sys.exit(0) |
113 |
+ |
114 |
if len(sys.argv) > 2: |
115 |
OLD_REL = sys.argv[2] |
116 |
if len(sys.argv) > 3: |
117 |
NEW_REL = sys.argv[3] |
118 |
+ |
119 |
ARCHES = None |
120 |
if STABLE: |
121 |
ARCHES = STABLE_ARCHES |
122 |
else: |
123 |
ARCHES = UNSTABLE_ARCHES |
124 |
|
125 |
-if os.environ.has_key('CHECK_DEPS'): |
126 |
+if 'CHECK_DEPS' in os.environ: |
127 |
CHECK_DEPS = os.environ['CHECK_DEPS'] |
128 |
|
129 |
-if os.environ.has_key('APPEND_SLOTS'): |
130 |
+if 'APPEND_SLOTS' in os.environ: |
131 |
APPEND_SLOTS = os.environ['APPEND_SLOTS'] |
132 |
|
133 |
if not STABLE: |
134 |
@@ -89,30 +98,35 @@ if not STABLE: |
135 |
print 'Please set STABLE to True' |
136 |
sys.exit(1) |
137 |
|
138 |
-###################### |
139 |
-## Define Functions ## |
140 |
-###################### |
141 |
+ |
142 |
+#################### |
143 |
+# Define Functions # |
144 |
+#################### |
145 |
def flatten(list, sep=' '): |
146 |
"Given a list, returns a flat string separated by 'sep'" |
147 |
return sep.join(list) |
148 |
|
149 |
+ |
150 |
def n_sep(n, sep=' '): |
151 |
tmp = '' |
152 |
for i in range(0, n): |
153 |
tmp += sep |
154 |
return tmp |
155 |
|
156 |
+ |
157 |
def debug(*strings): |
158 |
from portage.output import EOutput |
159 |
ewarn = EOutput().ewarn |
160 |
ewarn(flatten(strings)) |
161 |
|
162 |
+ |
163 |
def nothing_to_be_done(atom, type='cpv'): |
164 |
if STABLE: |
165 |
debug('%s %s: already stable, ignoring...' % (type, atom)) |
166 |
else: |
167 |
debug('%s %s: already keyworded, ignoring...' % (type, atom)) |
168 |
|
169 |
+ |
170 |
def make_unstable(kws): |
171 |
"Takes a keyword list, and returns a list with them all unstable" |
172 |
nkws = [] |
173 |
@@ -123,6 +137,7 @@ def make_unstable(kws): |
174 |
nkws.append(kw) |
175 |
return nkws |
176 |
|
177 |
+ |
178 |
def belongs_release(cpv, release): |
179 |
"Check if the given cpv belongs to the given release" |
180 |
# FIXME: This failure function needs better logic |
181 |
@@ -130,12 +145,14 @@ def belongs_release(cpv, release): |
182 |
raise Exception('This function is utterly useless with RECURSIVE mode') |
183 |
return get_ver(cpv).startswith(release) |
184 |
|
185 |
+ |
186 |
def issystempackage(cpv): |
187 |
for i in SYSTEM_PACKAGES: |
188 |
if cpv.startswith(i): |
189 |
return True |
190 |
return False |
191 |
|
192 |
+ |
193 |
def get_kws(cpv, arches=ARCHES): |
194 |
""" |
195 |
Returns an array of KEYWORDS matching 'arches' |
196 |
@@ -146,6 +163,7 @@ def get_kws(cpv, arches=ARCHES): |
197 |
kws.append(kw) |
198 |
return kws |
199 |
|
200 |
+ |
201 |
def do_not_want(cpv, release=None): |
202 |
""" |
203 |
Check if a package atom is p.masked or has empty keywords, or does not |
204 |
@@ -156,6 +174,7 @@ def do_not_want(cpv, release=None): |
205 |
return True |
206 |
return False |
207 |
|
208 |
+ |
209 |
def match_wanted_atoms(atom, release=None): |
210 |
""" |
211 |
Given an atom and a release, return all matching wanted atoms ordered in |
212 |
@@ -163,7 +182,8 @@ def match_wanted_atoms(atom, release=None): |
213 |
""" |
214 |
atoms = [] |
215 |
# xmatch is stupid, and ignores ! in an atom... |
216 |
- if atom.startswith('!'): return [] |
217 |
+ if atom.startswith('!'): |
218 |
+ return [] |
219 |
for cpv in portage.portdb.xmatch('match-all', atom): |
220 |
if do_not_want(cpv, release): |
221 |
continue |
222 |
@@ -171,14 +191,15 @@ def match_wanted_atoms(atom, release=None): |
223 |
atoms.reverse() |
224 |
return atoms |
225 |
|
226 |
+ |
227 |
def get_best_deps(cpv, kws, release=None): |
228 |
""" |
229 |
- Returns a list of the best deps of a cpv, optionally matching a release, and |
230 |
- with max of the specified keywords |
231 |
+ Returns a list of the best deps of a cpv, optionally matching a release, |
232 |
+ and with max of the specified keywords |
233 |
""" |
234 |
atoms = portage.portdb.aux_get(cpv, ['DEPEND', 'RDEPEND', 'PDEPEND']) |
235 |
- atoms = ' '.join(atoms).split() # consolidate atoms |
236 |
- atoms = list(set(atoms)) # de-duplicate |
237 |
+ atoms = ' '.join(atoms).split() # consolidate atoms |
238 |
+ atoms = list(set(atoms)) # de-duplicate |
239 |
deps = set() |
240 |
tmp = [] |
241 |
for atom in atoms: |
242 |
@@ -187,7 +208,8 @@ def get_best_deps(cpv, kws, release=None): |
243 |
continue |
244 |
ret = match_wanted_atoms(atom, release) |
245 |
if not ret: |
246 |
- if DEBUG: debug('We encountered an irrelevant atom: %s' % atom) |
247 |
+ if DEBUG: |
248 |
+ debug('We encountered an irrelevant atom: %s' % atom) |
249 |
continue |
250 |
best_kws = ['', []] |
251 |
for i in ret: |
252 |
@@ -197,7 +219,8 @@ def get_best_deps(cpv, kws, release=None): |
253 |
cur_ukws = set(make_unstable(get_kws(i, arches=kws+ukws))) |
254 |
if cur_ukws.intersection(ukws) != set(ukws): |
255 |
best_kws = 'none' |
256 |
- if DEBUG: debug('Insufficient unstable keywords in: %s' % i) |
257 |
+ if DEBUG: |
258 |
+ debug('Insufficient unstable keywords in: %s' % i) |
259 |
continue |
260 |
cur_match_kws = get_kws(i, arches=kws) |
261 |
if set(cur_match_kws) == set(kws): |
262 |
@@ -212,14 +235,16 @@ def get_best_deps(cpv, kws, release=None): |
263 |
# keywords that *we checked* (i.e. kws). |
264 |
best_kws = [i, []] |
265 |
if best_kws == 'alreadythere': |
266 |
- if DEBUG: nothing_to_be_done(atom, type='dep') |
267 |
+ if DEBUG: |
268 |
+ nothing_to_be_done(atom, type='dep') |
269 |
continue |
270 |
elif best_kws == 'none': |
271 |
continue |
272 |
elif not best_kws[0]: |
273 |
# We get this when the if STABLE: block above rejects everything. |
274 |
- # This means that this atom does not have any versions with unstable |
275 |
- # keywords matching the unstable keywords of the cpv that pulls it. |
276 |
+ # This means that this atom does not have any versions with |
277 |
+ # unstable keywords matching the unstable keywords of the cpv |
278 |
+ # that pulls it. |
279 |
# This mostly happens because an || or use dep exists. However, we |
280 |
# make such deps strict while parsing |
281 |
# XXX: We arbitrarily select the most recent version for this case |
282 |
@@ -239,15 +264,16 @@ def get_best_deps(cpv, kws, release=None): |
283 |
if len(cur_kws) > len(best_kws[1]): |
284 |
best_kws = [i, cur_kws] |
285 |
elif not best_kws[0]: |
286 |
- # This means that none of the versions have any of the stable |
287 |
- # keywords *at all*. No choice but to arbitrarily select the |
288 |
- # latest version in that case. |
289 |
+ # This means that none of the versions have any of |
290 |
+ # the stable keywords *at all*. No choice but to |
291 |
+ # arbitrarily select the latest version in that case. |
292 |
best_kws = [i, []] |
293 |
deps.add(best_kws[0]) |
294 |
else: |
295 |
deps.add(best_kws[0]) |
296 |
return list(deps) |
297 |
|
298 |
+ |
299 |
def max_kws(cpv, release=None): |
300 |
""" |
301 |
Given a cpv, find the intersection of "most keywords it can have" and |
302 |
@@ -259,7 +285,7 @@ def max_kws(cpv, release=None): |
303 |
Returns None if no cpv has keywords |
304 |
""" |
305 |
current_kws = get_kws(cpv, arches=ALL_ARCHES) |
306 |
- maximum_kws = [] # Maximum keywords that a cpv has |
307 |
+ maximum_kws = [] # Maximum keywords that a cpv has |
308 |
missing_kws = [] |
309 |
for atom in match_wanted_atoms('<='+cpv, release): |
310 |
kws = get_kws(atom) |
311 |
@@ -277,6 +303,7 @@ def max_kws(cpv, release=None): |
312 |
# No cpv has the keywords we need |
313 |
return None |
314 |
|
315 |
+ |
316 |
# FIXME: This is broken |
317 |
def kws_wanted(cpv_kws, prev_cpv_kws): |
318 |
"Generate a list of kws that need to be updated" |
319 |
@@ -289,13 +316,15 @@ def kws_wanted(cpv_kws, prev_cpv_kws): |
320 |
wanted.append(kw) |
321 |
return wanted |
322 |
|
323 |
+ |
324 |
def gen_cpv_kws(cpv, kws_aim, depgraph): |
325 |
depgraph.add(cpv) |
326 |
cpv_kw_list = [[cpv, kws_wanted(get_kws(cpv, arches=ALL_ARCHES), kws_aim)]] |
327 |
if not cpv_kw_list[0][1]: |
328 |
# This happens when cpv has less keywords than kws_aim |
329 |
- # Usually happens when a dep was an || dep, or under a USE-flag which is |
330 |
- # masked in some profiles. We make all deps strict in get_best_deps() |
331 |
+ # Usually happens when a dep was an || dep, or under a USE-flag |
332 |
+ # which is masked in some profiles. We make all deps strict in |
333 |
+ # get_best_deps() |
334 |
# So... let's just stabilize it on all arches we can, and ignore for |
335 |
# keywording since we have no idea about that. |
336 |
if not STABLE: |
337 |
@@ -322,6 +351,7 @@ def gen_cpv_kws(cpv, kws_aim, depgraph): |
338 |
cpv_kw_list.reverse() |
339 |
return cpv_kw_list |
340 |
|
341 |
+ |
342 |
def fix_nesting(nested_list): |
343 |
"""Takes a list of unknown nesting depth, and gives a nice list with each |
344 |
element of the form [cpv, [kws]]""" |
345 |
@@ -340,6 +370,7 @@ def fix_nesting(nested_list): |
346 |
index += 1 |
347 |
return nice_list |
348 |
|
349 |
+ |
350 |
def consolidate_dupes(cpv_kws): |
351 |
""" |
352 |
Consolidate duplicate cpvs with differing keywords |
353 |
@@ -355,7 +386,7 @@ def consolidate_dupes(cpv_kws): |
354 |
if type(each) is not list: |
355 |
continue |
356 |
else: |
357 |
- if not cpv_indices.has_key(each[0]): |
358 |
+ if each[0] not in cpv_indices: |
359 |
cpv_indices[each[0]] = [] |
360 |
cpv_indices[each[0]].append(cpv_kws.index(each)) |
361 |
|
362 |
@@ -388,6 +419,7 @@ def consolidate_dupes(cpv_kws): |
363 |
|
364 |
return deduped_cpv_kws |
365 |
|
366 |
+ |
367 |
def get_per_slot_cpvs(cpvs): |
368 |
"Classify the given cpvs into slots, and yield the best atom for each slot" |
369 |
slots = set() |
370 |
@@ -398,6 +430,7 @@ def get_per_slot_cpvs(cpvs): |
371 |
slots.add(slot) |
372 |
yield cpv |
373 |
|
374 |
+ |
375 |
def append_slots(cpv_kws): |
376 |
"Append slots at the end of cpv atoms" |
377 |
slotifyed_cpv_kws = [] |
378 |
@@ -407,6 +440,7 @@ def append_slots(cpv_kws): |
379 |
slotifyed_cpv_kws.append([cpv, kws]) |
380 |
return slotifyed_cpv_kws |
381 |
|
382 |
+ |
383 |
# FIXME: This is broken |
384 |
def prettify(cpv_kws): |
385 |
"Takes a list of [cpv, [kws]] and prettifies it" |
386 |
@@ -454,9 +488,10 @@ def prettify(cpv_kws): |
387 |
pretty_list.append([each[0], each[1]]) |
388 |
return pretty_list |
389 |
|
390 |
-####################### |
391 |
-## Use the Functions ## |
392 |
-####################### |
393 |
+ |
394 |
+##################### |
395 |
+# Use the Functions # |
396 |
+##################### |
397 |
# cpvs that will make it to the final list |
398 |
if __name__ == "__main__": |
399 |
index = 0 |
400 |
@@ -485,8 +520,8 @@ if __name__ == "__main__": |
401 |
# Current cpv has the max keywords => nothing to do |
402 |
nothing_to_be_done(cpv) |
403 |
continue |
404 |
- elif kws_missing == None: |
405 |
- debug ('No versions with stable keywords for %s' % cpv) |
406 |
+ elif kws_missing is None: |
407 |
+ debug('No versions with stable keywords for %s' % cpv) |
408 |
# No cpv with stable keywords => select latest |
409 |
arches = make_unstable(ARCHES) |
410 |
kws_missing = [kw[1:] for kw in get_kws(cpv, arches)] |