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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 tests=None, configs=None, dry_run=False, | 68 tests=None, configs=None, dry_run=False, |
69 add_new=False, missing_json_is_fatal=False): | 69 add_new=False, missing_json_is_fatal=False): |
70 self._expectations_root = expectations_root | 70 self._expectations_root = expectations_root |
71 self._tests = tests | 71 self._tests = tests |
72 self._configs = configs | 72 self._configs = configs |
73 self._json_base_url = json_base_url | 73 self._json_base_url = json_base_url |
74 self._json_filename = json_filename | 74 self._json_filename = json_filename |
75 self._dry_run = dry_run | 75 self._dry_run = dry_run |
76 self._add_new = add_new | 76 self._add_new = add_new |
77 self._missing_json_is_fatal = missing_json_is_fatal | 77 self._missing_json_is_fatal = missing_json_is_fatal |
78 self._googlestorage_gm_actuals_root = ( | 78 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN) |
79 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm') | |
80 self._testname_pattern = re.compile('(\S+)_(\S+).png') | |
81 self._is_svn_checkout = ( | 79 self._is_svn_checkout = ( |
82 os.path.exists(os.path.join(expectations_root, '.svn')) or | 80 os.path.exists(os.path.join(expectations_root, '.svn')) or |
83 os.path.exists(os.path.join(expectations_root, os.pardir, '.svn'))) | 81 os.path.exists(os.path.join(expectations_root, os.pardir, '.svn'))) |
84 self._is_git_checkout = ( | 82 self._is_git_checkout = ( |
85 os.path.exists(os.path.join(expectations_root, '.git')) or | 83 os.path.exists(os.path.join(expectations_root, '.git')) or |
86 os.path.exists(os.path.join(expectations_root, os.pardir, '.git'))) | 84 os.path.exists(os.path.join(expectations_root, os.pardir, '.git'))) |
87 | 85 |
88 # If dry_run is False, execute subprocess.call(cmd). | 86 # If dry_run is False, execute subprocess.call(cmd). |
89 # If dry_run is True, print the command we would have otherwise run. | 87 # If dry_run is True, print the command we would have otherwise run. |
90 # Raises a CommandFailedException if the command fails. | 88 # Raises a CommandFailedException if the command fails. |
91 def _Call(self, cmd): | 89 def _Call(self, cmd): |
92 if self._dry_run: | 90 if self._dry_run: |
93 print '%s' % ' '.join(cmd) | 91 print '%s' % ' '.join(cmd) |
94 return | 92 return |
95 if subprocess.call(cmd) != 0: | 93 if subprocess.call(cmd) != 0: |
96 raise CommandFailedException('error running command: ' + | 94 raise CommandFailedException('error running command: ' + |
97 ' '.join(cmd)) | 95 ' '.join(cmd)) |
98 | 96 |
99 # Download a single actual result from GoogleStorage. | 97 # Download a single actual result from GoogleStorage. |
100 # Raises an exception if it fails. | 98 # Raises an exception if it fails. |
101 def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): | 99 def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): |
102 test_name = self._testname_pattern.match(infilename).group(1) | 100 test_name = self._image_filename_re.match(infilename).group(1) |
103 if not test_name: | 101 if not test_name: |
104 raise Exception('unable to find test_name for infilename %s' % | 102 raise Exception('unable to find test_name for infilename %s' % |
105 infilename) | 103 infilename) |
106 try: | 104 try: |
107 hash_type, hash_value = all_results[infilename] | 105 hash_type, hash_value = all_results[infilename] |
108 except KeyError: | 106 except KeyError: |
109 raise Exception('unable to find filename %s in all_results dict' % | 107 raise Exception('unable to find filename %s in all_results dict' % |
110 infilename) | 108 infilename) |
111 except ValueError as e: | 109 except ValueError as e: |
112 raise Exception( | 110 raise Exception( |
113 'ValueError reading filename %s from all_results dict: %s' % ( | 111 'ValueError reading filename %s from all_results dict: %s' % ( |
114 infilename, e)) | 112 infilename, e)) |
115 url = '%s/%s/%s/%s.png' % (self._googlestorage_gm_actuals_root, | 113 url = gm_json.CreateGmActualUrl( |
116 hash_type, test_name, hash_value) | 114 test_name=test_name, hash_type=hash_type, hash_digest=hash_value) |
117 try: | 115 try: |
118 self._DownloadFile(source_url=url, dest_filename=outfilename) | 116 self._DownloadFile(source_url=url, dest_filename=outfilename) |
119 except CommandFailedException: | 117 except CommandFailedException: |
120 raise Exception('Couldn\'t fetch gs_url %s as outfile %s' % ( | 118 raise Exception('Couldn\'t fetch gs_url %s as outfile %s' % ( |
121 url, outfilename)) | 119 url, outfilename)) |
122 | 120 |
123 # Download a single file, raising a CommandFailedException if it fails. | 121 # Download a single file, raising a CommandFailedException if it fails. |
124 def _DownloadFile(self, source_url, dest_filename): | 122 def _DownloadFile(self, source_url, dest_filename): |
125 # Download into a temporary file and then rename it afterwards, | 123 # Download into a temporary file and then rename it afterwards, |
126 # so that we don't corrupt the existing file if it fails midway thru. | 124 # so that we don't corrupt the existing file if it fails midway thru. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 'gm-expected directory?') % (subdir, self._expectations_root)) | 258 'gm-expected directory?') % (subdir, self._expectations_root)) |
261 | 259 |
262 json_url = '/'.join([self._json_base_url, | 260 json_url = '/'.join([self._json_base_url, |
263 subdir, builder, subdir, | 261 subdir, builder, subdir, |
264 self._json_filename]) | 262 self._json_filename]) |
265 all_results = self._GetActualResults(json_url=json_url) | 263 all_results = self._GetActualResults(json_url=json_url) |
266 filenames = self._GetFilesToRebaseline(json_url=json_url, | 264 filenames = self._GetFilesToRebaseline(json_url=json_url, |
267 add_new=self._add_new) | 265 add_new=self._add_new) |
268 skipped_files = [] | 266 skipped_files = [] |
269 for filename in filenames: | 267 for filename in filenames: |
270 (test, config) = self._testname_pattern.match(filename).groups() | 268 (test, config) = self._image_filename_re.match(filename).groups() |
271 if self._tests: | 269 if self._tests: |
272 if test not in self._tests: | 270 if test not in self._tests: |
273 skipped_files.append(filename) | 271 skipped_files.append(filename) |
274 continue | 272 continue |
275 if self._configs: | 273 if self._configs: |
276 if config not in self._configs: | 274 if config not in self._configs: |
277 skipped_files.append(filename) | 275 skipped_files.append(filename) |
278 continue | 276 continue |
279 outfilename = os.path.join(self._expectations_root, subdir, | 277 outfilename = os.path.join(self._expectations_root, subdir, |
280 filename); | 278 filename); |
281 # TODO(epoger): Until we resolve | 279 # TODO(epoger): Until we resolve |
282 # https://code.google.com/p/skia/issues/detail?id=1410 ('some GM | 280 # https://code.google.com/p/skia/issues/detail?id=1410 ('some GM |
283 # result images not available for download from Google Storage'), | 281 # result images not available for download from Google Storage'), |
284 # keep going in the face of missing results for any one test. | 282 # keep going in the face of missing results for any one test. |
285 try: | 283 try: |
286 self._RebaselineOneFile(expectations_subdir=subdir, | 284 self._RebaselineOneFile(expectations_subdir=subdir, |
287 builder_name=builder, | 285 builder_name=builder, |
288 infilename=filename, | 286 infilename=filename, |
289 outfilename=outfilename, | 287 outfilename=outfilename, |
290 all_results=all_results) | 288 all_results=all_results) |
291 except Exception as e: | 289 except Exception as e: |
292 print 'WARNING: swallowing exception %s' % e | 290 print 'WARNING: swallowing exception %s' % e |
OLD | NEW |