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 ''' |
11 Rebaselines GM test results as individual image files | 11 Rebaselines GM test results as individual image files |
12 (the "old way", before https://goto.google.com/ChecksumTransitionDetail ). | 12 (the "old way", before https://goto.google.com/ChecksumTransitionDetail ). |
13 | 13 |
14 Once we have switched our expectations to JSON form for all platforms, | 14 Once we have switched our expectations to JSON form for all platforms, |
15 we can delete this file. | 15 we can delete this file. |
16 | 16 |
17 There is a lot of code duplicated between here and rebaseline.py, but | 17 There is a lot of code duplicated between here and rebaseline.py, but |
18 that's fine because we will delete this file soon. | 18 that's fine because we will delete this file soon. |
| 19 |
| 20 TODO(epoger): Fix indentation in this file (2-space indents, not 4-space). |
19 ''' | 21 ''' |
20 | 22 |
21 # System-level imports | 23 # System-level imports |
22 import os | 24 import os |
23 import re | 25 import re |
24 import subprocess | 26 import subprocess |
25 import sys | 27 import sys |
26 import urllib2 | 28 import urllib2 |
27 | 29 |
28 # Imports from within Skia | 30 # Imports from within Skia |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 add_new=False, missing_json_is_fatal=False): | 72 add_new=False, missing_json_is_fatal=False): |
71 self._expectations_root = expectations_root | 73 self._expectations_root = expectations_root |
72 self._tests = tests | 74 self._tests = tests |
73 self._configs = configs | 75 self._configs = configs |
74 self._json_base_url = json_base_url | 76 self._json_base_url = json_base_url |
75 self._json_filename = json_filename | 77 self._json_filename = json_filename |
76 self._exception_handler = exception_handler | 78 self._exception_handler = exception_handler |
77 self._dry_run = dry_run | 79 self._dry_run = dry_run |
78 self._add_new = add_new | 80 self._add_new = add_new |
79 self._missing_json_is_fatal = missing_json_is_fatal | 81 self._missing_json_is_fatal = missing_json_is_fatal |
80 self._googlestorage_gm_actuals_root = ( | 82 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN) |
81 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm') | |
82 self._testname_pattern = re.compile('(\S+)_(\S+).png') | |
83 self._is_svn_checkout = ( | 83 self._is_svn_checkout = ( |
84 os.path.exists(os.path.join(expectations_root, '.svn')) or | 84 os.path.exists(os.path.join(expectations_root, '.svn')) or |
85 os.path.exists(os.path.join(expectations_root, os.pardir, '.svn'))) | 85 os.path.exists(os.path.join(expectations_root, os.pardir, '.svn'))) |
86 self._is_git_checkout = ( | 86 self._is_git_checkout = ( |
87 os.path.exists(os.path.join(expectations_root, '.git')) or | 87 os.path.exists(os.path.join(expectations_root, '.git')) or |
88 os.path.exists(os.path.join(expectations_root, os.pardir, '.git'))) | 88 os.path.exists(os.path.join(expectations_root, os.pardir, '.git'))) |
89 | 89 |
90 # If dry_run is False, execute subprocess.call(cmd). | 90 # If dry_run is False, execute subprocess.call(cmd). |
91 # If dry_run is True, print the command we would have otherwise run. | 91 # If dry_run is True, print the command we would have otherwise run. |
92 # Raises a CommandFailedException if the command fails. | 92 # Raises a CommandFailedException if the command fails. |
93 def _Call(self, cmd): | 93 def _Call(self, cmd): |
94 if self._dry_run: | 94 if self._dry_run: |
95 print '%s' % ' '.join(cmd) | 95 print '%s' % ' '.join(cmd) |
96 return | 96 return |
97 if subprocess.call(cmd) != 0: | 97 if subprocess.call(cmd) != 0: |
98 raise CommandFailedException('error running command: ' + | 98 raise CommandFailedException('error running command: ' + |
99 ' '.join(cmd)) | 99 ' '.join(cmd)) |
100 | 100 |
101 # Download a single actual result from GoogleStorage. | 101 # Download a single actual result from GoogleStorage. |
102 # Raises an exception if it fails. | 102 # Raises an exception if it fails. |
103 def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): | 103 def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): |
104 test_name = self._testname_pattern.match(infilename).group(1) | 104 test_name = self._image_filename_re.match(infilename).group(1) |
105 if not test_name: | 105 if not test_name: |
106 raise Exception('unable to find test_name for infilename %s' % | 106 raise Exception('unable to find test_name for infilename %s' % |
107 infilename) | 107 infilename) |
108 try: | 108 try: |
109 hash_type, hash_value = all_results[infilename] | 109 hash_type, hash_value = all_results[infilename] |
110 except KeyError: | 110 except KeyError: |
111 raise Exception('unable to find filename %s in all_results dict' % | 111 raise Exception('unable to find filename %s in all_results dict' % |
112 infilename) | 112 infilename) |
113 except ValueError as e: | 113 except ValueError as e: |
114 raise Exception( | 114 raise Exception( |
115 'ValueError reading filename %s from all_results dict: %s' % ( | 115 'ValueError reading filename %s from all_results dict: %s' % ( |
116 infilename, e)) | 116 infilename, e)) |
117 url = '%s/%s/%s/%s.png' % (self._googlestorage_gm_actuals_root, | 117 url = gm_json.CreateGmActualUrl( |
118 hash_type, test_name, hash_value) | 118 test_name=test_name, hash_type=hash_type, hash_digest=hash_value) |
119 try: | 119 try: |
120 self._DownloadFile(source_url=url, dest_filename=outfilename) | 120 self._DownloadFile(source_url=url, dest_filename=outfilename) |
121 except CommandFailedException: | 121 except CommandFailedException: |
122 raise Exception('Couldn\'t fetch gs_url %s as outfile %s' % ( | 122 raise Exception('Couldn\'t fetch gs_url %s as outfile %s' % ( |
123 url, outfilename)) | 123 url, outfilename)) |
124 | 124 |
125 # Download a single file, raising a CommandFailedException if it fails. | 125 # Download a single file, raising a CommandFailedException if it fails. |
126 def _DownloadFile(self, source_url, dest_filename): | 126 def _DownloadFile(self, source_url, dest_filename): |
127 # Download into a temporary file and then rename it afterwards, | 127 # 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. | 128 # so that we don't corrupt the existing file if it fails midway thru. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 return | 263 return |
264 | 264 |
265 json_url = '/'.join([self._json_base_url, | 265 json_url = '/'.join([self._json_base_url, |
266 subdir, builder, subdir, | 266 subdir, builder, subdir, |
267 self._json_filename]) | 267 self._json_filename]) |
268 all_results = self._GetActualResults(json_url=json_url) | 268 all_results = self._GetActualResults(json_url=json_url) |
269 filenames = self._GetFilesToRebaseline(json_url=json_url, | 269 filenames = self._GetFilesToRebaseline(json_url=json_url, |
270 add_new=self._add_new) | 270 add_new=self._add_new) |
271 skipped_files = [] | 271 skipped_files = [] |
272 for filename in filenames: | 272 for filename in filenames: |
273 (test, config) = self._testname_pattern.match(filename).groups() | 273 (test, config) = self._image_filename_re.match(filename).groups() |
274 if self._tests: | 274 if self._tests: |
275 if test not in self._tests: | 275 if test not in self._tests: |
276 skipped_files.append(filename) | 276 skipped_files.append(filename) |
277 continue | 277 continue |
278 if self._configs: | 278 if self._configs: |
279 if config not in self._configs: | 279 if config not in self._configs: |
280 skipped_files.append(filename) | 280 skipped_files.append(filename) |
281 continue | 281 continue |
282 outfilename = os.path.join(self._expectations_root, subdir, | 282 outfilename = os.path.join(self._expectations_root, subdir, |
283 filename); | 283 filename); |
284 try: | 284 try: |
285 self._RebaselineOneFile(expectations_subdir=subdir, | 285 self._RebaselineOneFile(expectations_subdir=subdir, |
286 builder_name=builder, | 286 builder_name=builder, |
287 infilename=filename, | 287 infilename=filename, |
288 outfilename=outfilename, | 288 outfilename=outfilename, |
289 all_results=all_results) | 289 all_results=all_results) |
290 except BaseException as e: | 290 except BaseException as e: |
291 self._exception_handler.RaiseExceptionOrContinue(e) | 291 self._exception_handler.RaiseExceptionOrContinue(e) |
OLD | NEW |