OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Script to grab a list of ebuilds which cannot be safely mirrored. | |
7 | |
8 Some ebuilds do not have the proper versioning magic to be able to be safely | |
9 mirrored. We would like to phase them out gradually, by updating a list which | |
10 can be safely cached. | |
11 """ | |
12 | |
13 import os | |
14 import re | |
15 import StringIO | |
16 import tarfile | |
17 import urllib | |
18 | |
19 | |
20 def main(): | |
21 # Get a tarball of chromiumos-overlay. | |
22 fh = urllib.urlopen('http://src.chromium.org/cgi-bin/gitweb.cgi?' | |
23 'p=chromiumos-overlay.git;a=snapshot;h=HEAD;sf=tgz') | |
24 tgz = fh.read() | |
25 fh.close() | |
26 | |
27 # Prepare a set of files to clobber. | |
28 clobber_list = set() | |
29 # Prepare a set of files to exempt from clobbering. | |
30 exempt_list = set() | |
31 | |
32 # Walk the tarball looking for SAFE_TO_CACHE lists and ebuilds containing | |
33 # CHROMEOS_ROOT. | |
34 tgzf = StringIO.StringIO(tgz) | |
35 tar = tarfile.open(fileobj=tgzf, mode='r') | |
36 for tinfoi in tar: | |
37 if not tinfoi.isdir(): | |
38 original_name = tinfoi.name | |
39 tinfo = tinfoi | |
40 while tinfo.islnk() or tinfo.issym(): | |
41 path = os.path.normpath(os.path.join(os.path.dirname(tinfo.name), | |
42 tinfo.linkname)) | |
43 tinfo = tar.getmember(path) | |
44 if tinfo.name.endswith('.ebuild'): | |
45 # Load each ebuild. | |
46 fh = tar.extractfile(tinfo) | |
47 ebuild_data = fh.read() | |
48 fh.close() | |
49 # Add to the clobber list if it contains CHROMEOS_ROOT. | |
50 if 'CHROMEOS_ROOT' in ebuild_data: | |
51 filename = os.path.split(original_name)[1] | |
52 basename = os.path.splitext(filename)[0] | |
53 clobber_list.add(basename) | |
54 elif tinfo.name.endswith('/SAFE_TO_CACHE'): | |
55 fh = tar.extractfile(tinfo) | |
56 for line in fh: | |
57 if len(line) > 1 and line[0] != '#': | |
58 exempt_list.add(line.strip()) | |
59 fh.close() | |
60 tar.close() | |
61 tgzf.close() | |
62 | |
63 # Don't clobber ebuilds listed in SAFE_TO_CACHE. | |
64 clobber_list -= exempt_list | |
65 | |
66 # Scan the current directory for any Packages files, modify to remove | |
67 # packages that shouldn't be cached. | |
68 for root, _, files in os.walk('.', topdown=False): | |
69 for name in files: | |
70 filename = os.path.join(root, name) | |
71 basename = os.path.split(filename)[1] | |
72 if basename == 'Packages': | |
73 # Filter out entries involving uncache-able ebuilds. | |
74 allowed = True | |
75 nlines = [] | |
76 fh = open(filename, 'r') | |
77 for line in fh: | |
78 m = re.match('^CPV\: [^\n]+/([^/]+)[\n]$', line) | |
79 if m: | |
80 allowed = m.group(1) not in clobber_list | |
81 if allowed: | |
82 nlines.append(line) | |
83 fh.close() | |
84 # Write out new contents. | |
85 fh = open(filename, 'w') | |
86 for line in nlines: | |
87 fh.write(line) | |
88 fh.close() | |
89 | |
90 | |
91 if __name__ == '__main__': | |
92 main() | |
OLD | NEW |