1 |
commit: 6d936200f6324e340e823b7925c910d3c340b226 |
2 |
Author: Gilles Dartiguelongue <eva <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Jun 25 11:22:16 2015 +0000 |
4 |
Commit: Gilles Dartiguelongue <eva <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Jun 26 22:14:39 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gnome.git/commit/?id=6d936200 |
7 |
|
8 |
scripts/gen_archlist: rewrite consolidates_dupes using sets |
9 |
|
10 |
scripts/gen_archlist.py | 63 ++++++++++++++----------------------------------- |
11 |
1 file changed, 18 insertions(+), 45 deletions(-) |
12 |
|
13 |
diff --git a/scripts/gen_archlist.py b/scripts/gen_archlist.py |
14 |
index 659c84e..d595df3 100755 |
15 |
--- a/scripts/gen_archlist.py |
16 |
+++ b/scripts/gen_archlist.py |
17 |
@@ -24,6 +24,7 @@ |
18 |
from __future__ import division |
19 |
|
20 |
import argparse |
21 |
+import collections |
22 |
import os |
23 |
import sys |
24 |
|
25 |
@@ -41,7 +42,6 @@ UNSTABLE_ARCHES = ('~alpha', '~amd64', '~arm', '~hppa', '~ia64', '~m68k', |
26 |
'~x86-fbsd') |
27 |
ALL_ARCHES = STABLE_ARCHES + UNSTABLE_ARCHES |
28 |
SYSTEM_PACKAGES = [] |
29 |
-LINE_SEP = '' |
30 |
|
31 |
############ |
32 |
# Settings # |
33 |
@@ -348,52 +348,27 @@ def gen_cpv_kws(cpv, kws_aim, depgraph, check_dependencies, new_release): |
34 |
|
35 |
|
36 |
def consolidate_dupes(cpv_kws): |
37 |
- """ |
38 |
- Consolidate duplicate cpvs with differing keywords |
39 |
+ """Consolidate duplicate CPVs with differing keywords. |
40 |
|
41 |
- Cannot handle cps with different versions since we don't know if they are |
42 |
- inter-changeable |
43 |
+ Cannot handle CPs with different versions since we don't know if they are |
44 |
+ inter-changeable. |
45 |
""" |
46 |
- cpv_indices = {} |
47 |
- |
48 |
- # Find all indices of each cpv |
49 |
- for each in cpv_kws: |
50 |
- # Comments/whitespace carried over from original list |
51 |
- if type(each) is not list: |
52 |
- continue |
53 |
- else: |
54 |
- if each[0] not in cpv_indices: |
55 |
- cpv_indices[each[0]] = [] |
56 |
- cpv_indices[each[0]].append(cpv_kws.index(each)) |
57 |
+ # Build maximum requested keywords for each cpv |
58 |
+ cpv_kws_dict = collections.defaultdict(set) |
59 |
+ for dep_set in cpv_kws: |
60 |
+ for cpv, kws in dep_set: |
61 |
+ cpv_kws_dict[cpv].update(kws) |
62 |
|
63 |
- # Replace the keywords of each cpv with the union of all keywords in the |
64 |
- # list belonging to this cpv |
65 |
- for each in cpv_kws: |
66 |
- # Ignore comments/whitespace carried over from original list |
67 |
- if type(each) is not list: |
68 |
- continue |
69 |
- kws = set() |
70 |
- for index in cpv_indices[each[0]]: |
71 |
- kws.update(cpv_kws[index][1]) |
72 |
- each[1] = list(kws) |
73 |
- each[1].sort() |
74 |
- |
75 |
- index = 0 |
76 |
- deduped_cpv_kws = cpv_kws[:] |
77 |
- deduped_cpv_kws.reverse() |
78 |
- while index < len(deduped_cpv_kws): |
79 |
- item = deduped_cpv_kws[index] |
80 |
- if type(item) is not list: |
81 |
- index += 1 |
82 |
- continue |
83 |
- if deduped_cpv_kws.count(item) is 1: |
84 |
- index += 1 |
85 |
- else: |
86 |
- while deduped_cpv_kws.count(item) is not 1: |
87 |
- deduped_cpv_kws.remove(item) |
88 |
- deduped_cpv_kws.reverse() |
89 |
+ # Update cpv with their maximum request keywords |
90 |
+ clean_cpv_kws = [] |
91 |
+ for dep_set in cpv_kws: |
92 |
+ clean_cpv_kws.append([ |
93 |
+ (cpv, cpv_kws_dict.pop(cpv)) |
94 |
+ # Keep only first occurence of cpv |
95 |
+ for cpv, _ in dep_set if cpv in cpv_kws_dict |
96 |
+ ]) |
97 |
|
98 |
- return deduped_cpv_kws |
99 |
+ return clean_cpv_kws |
100 |
|
101 |
|
102 |
def get_per_slot_cpvs(cpvs): |
103 |
@@ -531,8 +506,6 @@ def main(): |
104 |
gen_cpv_kws(cpv, kws_missing, set([cpv]), |
105 |
args.check_dependencies, args.new_version) |
106 |
) |
107 |
- if args.check_dependencies: |
108 |
- ALL_CPV_KWS.append(LINE_SEP) |
109 |
|
110 |
ALL_CPV_KWS = consolidate_dupes(ALL_CPV_KWS) |
111 |
if args.append_slots: |