OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 ''' | 3 ''' |
4 Copyright 2013 Google Inc. | 4 Copyright 2013 Google Inc. |
5 | 5 |
6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
7 found in the LICENSE file. | 7 found in the LICENSE file. |
8 ''' | 8 ''' |
9 | 9 |
10 ''' | 10 ''' |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 # If dry_run is True, print the command we would have otherwise run. | 89 # If dry_run is True, print the command we would have otherwise run. |
90 # Raises a CommandFailedException if the command fails. | 90 # Raises a CommandFailedException if the command fails. |
91 def _Call(self, cmd): | 91 def _Call(self, cmd): |
92 if self._dry_run: | 92 if self._dry_run: |
93 print '%s' % ' '.join(cmd) | 93 print '%s' % ' '.join(cmd) |
94 return | 94 return |
95 if subprocess.call(cmd) != 0: | 95 if subprocess.call(cmd) != 0: |
96 raise CommandFailedException('error running command: ' + | 96 raise CommandFailedException('error running command: ' + |
97 ' '.join(cmd)) | 97 ' '.join(cmd)) |
98 | 98 |
99 # Download a single actual result from GoogleStorage, returning True if it | 99 # Download a single actual result from GoogleStorage. |
100 # succeeded. | 100 # Raises an exception if it fails. |
101 def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): | 101 def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): |
102 test_name = self._testname_pattern.match(infilename).group(1) | 102 test_name = self._testname_pattern.match(infilename).group(1) |
103 if not test_name: | 103 if not test_name: |
104 print '# unable to find test_name for infilename %s' % infilename | 104 raise Exception('unable to find test_name for infilename %s' % |
105 return False | 105 infilename) |
106 try: | 106 try: |
107 hash_type, hash_value = all_results[infilename] | 107 hash_type, hash_value = all_results[infilename] |
108 except KeyError: | 108 except KeyError: |
109 print ('# unable to find filename %s in all_results dict' % | 109 raise Exception('unable to find filename %s in all_results dict' % |
110 infilename) | 110 infilename) |
111 return False | |
112 except ValueError as e: | 111 except ValueError as e: |
113 print '# ValueError reading filename %s from all_results dict: %s'%( | 112 raise Exception( |
114 infilename, e) | 113 'ValueError reading filename %s from all_results dict: %s' % ( |
115 return False | 114 infilename, e)) |
116 url = '%s/%s/%s/%s.png' % (self._googlestorage_gm_actuals_root, | 115 url = '%s/%s/%s/%s.png' % (self._googlestorage_gm_actuals_root, |
117 hash_type, test_name, hash_value) | 116 hash_type, test_name, hash_value) |
118 try: | 117 try: |
119 self._DownloadFile(source_url=url, dest_filename=outfilename) | 118 self._DownloadFile(source_url=url, dest_filename=outfilename) |
120 return True | |
121 except CommandFailedException: | 119 except CommandFailedException: |
122 print '# Couldn\'t fetch gs_url %s' % url | 120 raise Exception('Couldn\'t fetch gs_url %s as outfile %s' % ( |
123 return False | 121 url, outfilename)) |
124 | 122 |
125 # Download a single file, raising a CommandFailedException if it fails. | 123 # Download a single file, raising a CommandFailedException if it fails. |
126 def _DownloadFile(self, source_url, dest_filename): | 124 def _DownloadFile(self, source_url, dest_filename): |
127 # Download into a temporary file and then rename it afterwards, | 125 # Download into a temporary file and then rename it afterwards, |
128 # so that we don't corrupt the existing file if it fails midway thru. | 126 # so that we don't corrupt the existing file if it fails midway thru. |
129 temp_filename = os.path.join(os.path.dirname(dest_filename), | 127 temp_filename = os.path.join(os.path.dirname(dest_filename), |
130 '.temp-' + os.path.basename(dest_filename)) | 128 '.temp-' + os.path.basename(dest_filename)) |
131 | 129 |
132 # TODO(epoger): Replace calls to "curl"/"mv" (which will only work on | 130 # TODO(epoger): Replace calls to "curl"/"mv" (which will only work on |
133 # Unix) with a Python HTTP library (which should work cross-platform) | 131 # Unix) with a Python HTTP library (which should work cross-platform) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 print '#' | 221 print '#' |
224 return files_to_rebaseline | 222 return files_to_rebaseline |
225 | 223 |
226 # Rebaseline a single file. | 224 # Rebaseline a single file. |
227 def _RebaselineOneFile(self, expectations_subdir, builder_name, | 225 def _RebaselineOneFile(self, expectations_subdir, builder_name, |
228 infilename, outfilename, all_results): | 226 infilename, outfilename, all_results): |
229 if self._dry_run: | 227 if self._dry_run: |
230 print '' | 228 print '' |
231 print '# ' + infilename | 229 print '# ' + infilename |
232 | 230 |
233 # Download this result image from Google Storage; if that fails, | 231 # Download this result image from Google Storage. |
234 # raise an exception (because if actual-results.json told us that | 232 # If it fails, an exception will be raised. |
235 # a particular image version is available for download, we should | 233 self._DownloadFromGoogleStorage(infilename=infilename, |
236 # always be able to get it!) | 234 outfilename=outfilename, |
237 if not self._DownloadFromGoogleStorage(infilename=infilename, | 235 all_results=all_results) |
238 outfilename=outfilename, | |
239 all_results=all_results): | |
240 raise Exception('# Couldn\'t fetch infilename ' + infilename) | |
241 | 236 |
242 # Add this file to version control (if appropriate). | 237 # Add this file to version control (if appropriate). |
243 if self._add_new: | 238 if self._add_new: |
244 if self._is_svn_checkout: | 239 if self._is_svn_checkout: |
245 cmd = [ 'svn', 'add', '--quiet', outfilename ] | 240 cmd = [ 'svn', 'add', '--quiet', outfilename ] |
246 self._Call(cmd) | 241 self._Call(cmd) |
247 cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', | 242 cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', |
248 'image/png', outfilename ]; | 243 'image/png', outfilename ]; |
249 self._Call(cmd) | 244 self._Call(cmd) |
250 elif self._is_git_checkout: | 245 elif self._is_git_checkout: |
251 cmd = [ 'git', 'add', outfilename ] | 246 cmd = [ 'git', 'add', outfilename ] |
252 self._Call(cmd) | 247 self._Call(cmd) |
253 | 248 |
254 # Rebaseline all tests/types we specified in the constructor, | 249 # Rebaseline all tests/types we specified in the constructor, |
255 # within this gm-expectations subdir. | 250 # within this gm-expectations subdir. |
256 # | 251 # |
257 # params: | 252 # params: |
258 # subdir : e.g. 'base-shuttle-win7-intel-float' | 253 # subdir : e.g. 'base-shuttle-win7-intel-float' |
259 # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release' | 254 # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release' |
260 def RebaselineSubdir(self, subdir, builder): | 255 def RebaselineSubdir(self, subdir, builder): |
| 256 if not os.path.isdir(os.path.join(self._expectations_root, subdir)): |
| 257 raise Exception(( |
| 258 'Could not find "%s" subdir within expectations_root "%s". ' + |
| 259 'Are you sure --expectations-root is pointing at a valid ' + |
| 260 'gm-expected directory?') % (subdir, self._expectations_root)) |
| 261 |
261 json_url = '/'.join([self._json_base_url, | 262 json_url = '/'.join([self._json_base_url, |
262 subdir, builder, subdir, | 263 subdir, builder, subdir, |
263 self._json_filename]) | 264 self._json_filename]) |
264 all_results = self._GetActualResults(json_url=json_url) | 265 all_results = self._GetActualResults(json_url=json_url) |
265 filenames = self._GetFilesToRebaseline(json_url=json_url, | 266 filenames = self._GetFilesToRebaseline(json_url=json_url, |
266 add_new=self._add_new) | 267 add_new=self._add_new) |
267 skipped_files = [] | 268 skipped_files = [] |
268 for filename in filenames: | 269 for filename in filenames: |
269 (test, config) = self._testname_pattern.match(filename).groups() | 270 (test, config) = self._testname_pattern.match(filename).groups() |
270 if self._tests: | 271 if self._tests: |
271 if test not in self._tests: | 272 if test not in self._tests: |
272 skipped_files.append(filename) | 273 skipped_files.append(filename) |
273 continue | 274 continue |
274 if self._configs: | 275 if self._configs: |
275 if config not in self._configs: | 276 if config not in self._configs: |
276 skipped_files.append(filename) | 277 skipped_files.append(filename) |
277 continue | 278 continue |
278 outfilename = os.path.join(subdir, filename); | 279 outfilename = os.path.join(self._expectations_root, subdir, |
| 280 filename); |
279 self._RebaselineOneFile(expectations_subdir=subdir, | 281 self._RebaselineOneFile(expectations_subdir=subdir, |
280 builder_name=builder, | 282 builder_name=builder, |
281 infilename=filename, | 283 infilename=filename, |
282 outfilename=outfilename, | 284 outfilename=outfilename, |
283 all_results=all_results) | 285 all_results=all_results) |
284 | |
285 if skipped_files: | |
286 print ('Skipped these files due to test/config filters: %s' % | |
287 skipped_files) | |
OLD | NEW |