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 Calulate differences between image pairs, and store them in a database. | 9 Calulate differences between image pairs, and store them in a database. |
10 """ | 10 """ |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
380 """Wrapper for Image.open(filepath) that yields more useful error messages. | 380 """Wrapper for Image.open(filepath) that yields more useful error messages. |
381 | 381 |
382 Args: | 382 Args: |
383 filepath: path on local disk to load image from | 383 filepath: path on local disk to load image from |
384 | 384 |
385 Returns: a PIL image object | 385 Returns: a PIL image object |
386 """ | 386 """ |
387 try: | 387 try: |
388 return Image.open(filepath) | 388 return Image.open(filepath) |
389 except IOError: | 389 except IOError: |
390 logging.error('IOError loading image file %s' % filepath) | 390 # If we are unable to load an image from the file, delete it from disk |
391 # and we will try to fetch it again next time. Fixes http://skbug.com/2247 | |
392 logging.error('IOError loading image file %s ; deleting it.' % filepath) | |
393 os.remove(filepath) | |
borenet
2014/03/26 13:17:21
Is there a chance that the file may not exist? I
epoger
2014/03/26 13:38:12
I suppose it's possible. For the reason you menti
| |
391 raise | 394 raise |
392 | 395 |
393 | 396 |
394 def _save_image(image, filepath, format='PNG'): | 397 def _save_image(image, filepath, format='PNG'): |
395 """Write an image to disk, creating any intermediate directories as needed. | 398 """Write an image to disk, creating any intermediate directories as needed. |
396 | 399 |
397 Args: | 400 Args: |
398 image: a PIL image object | 401 image: a PIL image object |
399 filepath: path on local disk to write image to | 402 filepath: path on local disk to write image to |
400 format: one of the PIL image formats, listed at | 403 format: one of the PIL image formats, listed at |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 | 436 |
434 Args: | 437 Args: |
435 expected_image_locator: locator string pointing at expected image | 438 expected_image_locator: locator string pointing at expected image |
436 actual_image_locator: locator string pointing at actual image | 439 actual_image_locator: locator string pointing at actual image |
437 | 440 |
438 Returns: already-sanitized locator where the diffs between expected and | 441 Returns: already-sanitized locator where the diffs between expected and |
439 actual images can be found | 442 actual images can be found |
440 """ | 443 """ |
441 return "%s-vs-%s" % (_sanitize_locator(expected_image_locator), | 444 return "%s-vs-%s" % (_sanitize_locator(expected_image_locator), |
442 _sanitize_locator(actual_image_locator)) | 445 _sanitize_locator(actual_image_locator)) |
OLD | NEW |