| OLD | NEW |
| 1 # Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged | 1 # Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
| 9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
| 10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
| 11 # | 11 # |
| 12 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 12 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 13 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 13 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 14 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 14 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 15 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 15 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 16 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 16 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 17 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 17 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 18 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 18 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 20 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 21 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | 23 |
| 24 | |
| 25 """Supports checking WebKit style in png files.""" | 24 """Supports checking WebKit style in png files.""" |
| 26 | 25 |
| 27 | |
| 28 from webkitpy.common import read_checksum_from_png | 26 from webkitpy.common import read_checksum_from_png |
| 29 from webkitpy.common.system.systemhost import SystemHost | 27 from webkitpy.common.system.systemhost import SystemHost |
| 30 from webkitpy.common.checkout.scm.detection import SCMDetector | |
| 31 | 28 |
| 32 | 29 |
| 33 class PNGChecker(object): | 30 class PNGChecker(object): |
| 34 """Check svn:mime-type for checking style""" | 31 """Check svn:mime-type for checking style""" |
| 35 | 32 |
| 36 categories = set(['image/png']) | 33 categories = set(['image/png']) |
| 37 | 34 |
| 38 def __init__(self, file_path, handle_style_error, host=None): | 35 def __init__(self, file_path, handle_style_error, host=None): |
| 39 self._file_path = file_path | 36 self._file_path = file_path |
| 40 self._handle_style_error = handle_style_error | 37 self._handle_style_error = handle_style_error |
| 41 self._host = host or SystemHost() | 38 self._host = host or SystemHost() |
| 42 self._fs = self._host.filesystem | 39 self._fs = self._host.filesystem |
| 43 | 40 |
| 44 def check(self, inline=None): | 41 def check(self, inline=None): |
| 45 if self._fs.exists(self._file_path) and self._file_path.endswith("-expec
ted.png"): | 42 if self._fs.exists(self._file_path) and self._file_path.endswith("-expec
ted.png"): |
| 46 with self._fs.open_binary_file_for_reading(self._file_path) as fileh
andle: | 43 with self._fs.open_binary_file_for_reading(self._file_path) as fileh
andle: |
| 47 if not read_checksum_from_png.read_checksum(filehandle): | 44 if not read_checksum_from_png.read_checksum(filehandle): |
| 48 self._handle_style_error( | 45 self._handle_style_error( |
| 49 0, 'image/png', 5, | 46 0, 'image/png', 5, |
| 50 "Image lacks a checksum. Generate pngs using run-webkit-
tests to ensure they have a checksum.") | 47 "Image lacks a checksum. Generate pngs using run-webkit-
tests to ensure they have a checksum.") |
| OLD | NEW |