OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 ''' | 3 ''' |
4 Copyright 2012 Google Inc. | 4 Copyright 2012 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 the given GM tests, on all bots and all configurations. | 11 Rebaselines the given GM tests, on all bots and all configurations. |
12 Must be run from the gm-expected directory. If run from a git or SVN | 12 Must be run from the gm-expected directory. If run from a git or SVN |
13 checkout, the files will be added to the staging area for commit. | 13 checkout, the files will be added to the staging area for commit. |
| 14 |
| 15 TODO(epoger): Fix indentation in this file (2-space indents, not 4-space). |
14 ''' | 16 ''' |
15 | 17 |
16 # System-level imports | 18 # System-level imports |
17 import argparse | 19 import argparse |
18 import os | 20 import os |
19 import re | 21 import re |
20 import sys | 22 import sys |
21 import urllib2 | 23 import urllib2 |
22 | 24 |
23 # Imports from local directory | 25 # Imports from local directory |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 actuals_base_url, actuals_filename, exception_handler, | 141 actuals_base_url, actuals_filename, exception_handler, |
140 tests=None, configs=None, add_new=False): | 142 tests=None, configs=None, add_new=False): |
141 self._expectations_root = expectations_root | 143 self._expectations_root = expectations_root |
142 self._expectations_filename = expectations_filename | 144 self._expectations_filename = expectations_filename |
143 self._tests = tests | 145 self._tests = tests |
144 self._configs = configs | 146 self._configs = configs |
145 self._actuals_base_url = actuals_base_url | 147 self._actuals_base_url = actuals_base_url |
146 self._actuals_filename = actuals_filename | 148 self._actuals_filename = actuals_filename |
147 self._exception_handler = exception_handler | 149 self._exception_handler = exception_handler |
148 self._add_new = add_new | 150 self._add_new = add_new |
149 self._testname_pattern = re.compile('(\S+)_(\S+).png') | 151 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN) |
150 | 152 |
151 # Returns the full contents of filepath, as a single string. | 153 # Returns the full contents of filepath, as a single string. |
152 # If filepath looks like a URL, try to read it that way instead of as | 154 # If filepath looks like a URL, try to read it that way instead of as |
153 # a path on local storage. | 155 # a path on local storage. |
154 # | 156 # |
155 # Raises _InternalException if there is a problem. | 157 # Raises _InternalException if there is a problem. |
156 def _GetFileContents(self, filepath): | 158 def _GetFileContents(self, filepath): |
157 if filepath.startswith('http:') or filepath.startswith('https:'): | 159 if filepath.startswith('http:') or filepath.startswith('https:'): |
158 try: | 160 try: |
159 return urllib2.urlopen(filepath).read() | 161 return urllib2.urlopen(filepath).read() |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 # Read in current expectations. | 225 # Read in current expectations. |
224 expectations_json_filepath = os.path.join( | 226 expectations_json_filepath = os.path.join( |
225 self._expectations_root, subdir, self._expectations_filename) | 227 self._expectations_root, subdir, self._expectations_filename) |
226 expectations_dict = gm_json.LoadFromFile(expectations_json_filepath) | 228 expectations_dict = gm_json.LoadFromFile(expectations_json_filepath) |
227 | 229 |
228 # Update the expectations in memory, skipping any tests/configs that | 230 # Update the expectations in memory, skipping any tests/configs that |
229 # the caller asked to exclude. | 231 # the caller asked to exclude. |
230 skipped_images = [] | 232 skipped_images = [] |
231 if results_to_update: | 233 if results_to_update: |
232 for (image_name, image_results) in results_to_update.iteritems(): | 234 for (image_name, image_results) in results_to_update.iteritems(): |
233 (test, config) = self._testname_pattern.match(image_name).groups
() | 235 (test, config) = \ |
| 236 self._image_filename_re.match(image_name).groups() |
234 if self._tests: | 237 if self._tests: |
235 if test not in self._tests: | 238 if test not in self._tests: |
236 skipped_images.append(image_name) | 239 skipped_images.append(image_name) |
237 continue | 240 continue |
238 if self._configs: | 241 if self._configs: |
239 if config not in self._configs: | 242 if config not in self._configs: |
240 skipped_images.append(image_name) | 243 skipped_images.append(image_name) |
241 continue | 244 continue |
242 expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] \ | 245 expectations_dict \ |
243 [image_name] \ | 246 [gm_json.JSONKEY_EXPECTEDRESULTS] \ |
244 [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS
] = \ | 247 [image_name] \ |
245 [image_results] | 248 [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS] = \ |
| 249 [image_results] |
246 | 250 |
247 # Write out updated expectations. | 251 # Write out updated expectations. |
248 gm_json.WriteToFile(expectations_dict, expectations_json_filepath) | 252 gm_json.WriteToFile(expectations_dict, expectations_json_filepath) |
249 | 253 |
250 | 254 |
251 # main... | 255 # main... |
252 | 256 |
253 parser = argparse.ArgumentParser() | 257 parser = argparse.ArgumentParser() |
254 parser.add_argument('--actuals-base-url', | 258 parser.add_argument('--actuals-base-url', |
255 help='base URL from which to read files containing JSON ' + | 259 help='base URL from which to read files containing JSON ' + |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 exception_handler=exception_handler, | 356 exception_handler=exception_handler, |
353 add_new=args.add_new, | 357 add_new=args.add_new, |
354 missing_json_is_fatal=missing_json_is_fatal) | 358 missing_json_is_fatal=missing_json_is_fatal) |
355 | 359 |
356 try: | 360 try: |
357 rebaseliner.RebaselineSubdir(subdir=subdir, builder=builder) | 361 rebaseliner.RebaselineSubdir(subdir=subdir, builder=builder) |
358 except BaseException as e: | 362 except BaseException as e: |
359 exception_handler.RaiseExceptionOrContinue(e) | 363 exception_handler.RaiseExceptionOrContinue(e) |
360 | 364 |
361 exception_handler.ReportAllFailures() | 365 exception_handler.ReportAllFailures() |
OLD | NEW |