OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 | |
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 | |
8 """ find_missing_images: Look through skia-autogen, searching for all checksums | |
epoger
2013/07/10 19:30:44
Delete no-longer-accurate script name
borenet
2013/07/10 20:36:45
Done.
| |
9 which should have corresponding files in Google Storage, and verify that those | |
10 files exist. """ | |
11 | |
12 | |
13 import json | |
14 import posixpath | |
15 import subprocess | |
16 import sys | |
17 | |
18 | |
19 AUTOGEN_URL = 'http://skia-autogen.googlecode.com/svn/gm-actual' | |
epoger
2013/07/10 19:30:44
optional: use argparse with defaults (like https:/
borenet
2013/07/10 20:36:45
Mind if I save this for the future? I'd like to j
epoger
2013/07/11 14:14:25
No problem.
| |
20 GS_URL = 'gs://chromium-skia-gm/gm/' | |
21 | |
22 | |
23 def FileNameToResultType(filename): | |
epoger
2013/07/10 19:30:44
please add a brief description of each function
borenet
2013/07/10 20:36:45
Done.
| |
24 result = filename | |
25 for suffix in ['.png', '_8888', '_565', '_gpu', '_gpudebug', '_msaa4']: | |
epoger
2013/07/10 19:30:44
I don't understand why we need this list of suffix
borenet
2013/07/10 20:36:45
Done.
| |
26 if result.endswith(suffix): | |
27 result = result[:len(result) - len(suffix)] | |
28 return result | |
29 | |
30 | |
31 def FindChecksumsInJSON(json_file): | |
32 print 'svn cat %s' % json_file | |
33 output = subprocess.check_output(['svn', 'cat', json_file]) | |
34 json_content = json.loads(output) | |
35 checksums = [] | |
36 for dict_type in ['actual-results']: | |
37 for result_type in json_content[dict_type]: | |
38 if json_content[dict_type][result_type]: | |
39 for result in json_content[dict_type][result_type].keys(): | |
40 hash_type, hash = json_content[dict_type][result_type][result] | |
41 checksum = posixpath.join(hash_type, | |
42 FileNameToResultType(result), | |
43 str(hash)) | |
44 checksums.append(checksum) | |
45 return checksums | |
46 | |
47 | |
48 def _FindJSONFiles(url, json_files): | |
49 proc = subprocess.Popen(['svn', 'ls', url], stdout=subprocess.PIPE, | |
50 stderr=subprocess.STDOUT) | |
51 if proc.wait() != 0: | |
52 raise Exception('Failed to list svn directory.') | |
53 output = proc.communicate()[0].splitlines() | |
54 subdirs = [] | |
55 for item in output: | |
56 if item.endswith(posixpath.sep): | |
57 subdirs.append(item) | |
58 elif item.endswith('.json'): | |
59 json_files.append(posixpath.join(url, item)) | |
60 else: | |
61 print 'Warning: ignoring %s' % posixpath.join(url, item) | |
62 for subdir in subdirs: | |
63 _FindJSONFiles(posixpath.join(url, subdir), json_files) | |
64 | |
65 | |
66 def FindJSONFiles(url): | |
67 print 'Searching for json files in %s' % url | |
68 json_files = [] | |
69 _FindJSONFiles(url, json_files) | |
70 return json_files | |
71 | |
72 | |
73 def FindChecksums(url): | |
74 checksums = set() | |
75 for json_file in FindJSONFiles(url): | |
76 print 'Looking for checksums in %s' % json_file | |
77 checksums.update(FindChecksumsInJSON(json_file)) | |
78 return checksums | |
79 | |
80 | |
81 def VerifyChecksum(checksum): | |
82 image_url = posixpath.join(GS_URL, checksum + '.png') | |
83 proc = subprocess.Popen(['gsutil', 'ls', image_url], stdout=subprocess.PIPE, | |
84 stderr=subprocess.STDOUT) | |
85 if proc.wait() != 0: | |
86 return False | |
87 return True | |
88 | |
89 | |
90 def VerifyChecksums(checksums): | |
91 print 'Verifying that images exist for checksums...' | |
92 missing = [] | |
93 for checksum in checksums: | |
94 if not VerifyChecksum(checksum): | |
95 print 'Missing: %s' % checksum | |
96 missing.append(checksum) | |
97 return missing | |
98 | |
99 | |
100 def Main(): | |
101 checksums = FindChecksums(AUTOGEN_URL) | |
102 missing = VerifyChecksums(checksums) | |
103 if missing: | |
104 print 'Missing files:' | |
epoger
2013/07/10 19:30:44
please print the number of missing files
borenet
2013/07/10 20:36:45
Done.
| |
105 print '\n'.join(missing) | |
106 return 1 | |
107 | |
108 | |
109 if __name__ == '__main__': | |
110 sys.exit(Main()) | |
OLD | NEW |