| OLD | NEW |
| (Empty) |
| 1 # Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions | |
| 5 # are met: | |
| 6 # 1. Redistributions of source code must retain the above copyright | |
| 7 # notice, this list of conditions and the following disclaimer. | |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | |
| 9 # notice, this list of conditions and the following disclaimer in the | |
| 10 # documentation and/or other materials provided with the distribution. | |
| 11 # | |
| 12 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 13 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 14 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 15 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 16 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 17 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 18 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 19 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 20 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 23 | |
| 24 | |
| 25 """Supports checking WebKit style in png files.""" | |
| 26 | |
| 27 import os | |
| 28 import re | |
| 29 | |
| 30 from webkitpy.common import checksvnconfigfile | |
| 31 from webkitpy.common import read_checksum_from_png | |
| 32 from webkitpy.common.system.systemhost import SystemHost | |
| 33 from webkitpy.common.checkout.scm.detection import SCMDetector | |
| 34 | |
| 35 class PNGChecker(object): | |
| 36 """Check svn:mime-type for checking style""" | |
| 37 | |
| 38 categories = set(['image/png']) | |
| 39 | |
| 40 def __init__(self, file_path, handle_style_error, scm=None, host=None): | |
| 41 self._file_path = file_path | |
| 42 self._handle_style_error = handle_style_error | |
| 43 self._host = host or SystemHost() | |
| 44 self._fs = self._host.filesystem | |
| 45 self._detector = scm or SCMDetector(self._fs, self._host.executive).dete
ct_scm_system(self._fs.getcwd()) | |
| 46 | |
| 47 def check(self, inline=None): | |
| 48 errorstr = "" | |
| 49 config_file_path = "" | |
| 50 detection = self._detector.display_name() | |
| 51 | |
| 52 if self._fs.exists(self._file_path) and self._file_path.endswith("-expec
ted.png"): | |
| 53 with self._fs.open_binary_file_for_reading(self._file_path) as fileh
andle: | |
| 54 if not read_checksum_from_png.read_checksum(filehandle): | |
| 55 self._handle_style_error(0, 'image/png', 5, "Image lacks a c
hecksum. Generate pngs using run-webkit-tests to ensure they have a checksum.") | |
| 56 | |
| 57 if detection == "git": | |
| 58 (file_missing, autoprop_missing, png_missing) = checksvnconfigfile.c
heck(self._host, self._fs) | |
| 59 config_file_path = checksvnconfigfile.config_file_path(self._host, s
elf._fs) | |
| 60 | |
| 61 if file_missing: | |
| 62 self._handle_style_error(0, 'image/png', 5, "There is no SVN con
fig file. (%s)" % config_file_path) | |
| 63 elif autoprop_missing and png_missing: | |
| 64 self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.e
rrorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file
_path)) | |
| 65 elif autoprop_missing: | |
| 66 self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.e
rrorstr_autoprop(config_file_path)) | |
| 67 elif png_missing: | |
| 68 self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.e
rrorstr_png(config_file_path)) | |
| 69 | |
| 70 elif detection == "svn": | |
| 71 prop_get = self._detector.propget("svn:mime-type", self._file_path) | |
| 72 if prop_get != "image/png": | |
| 73 errorstr = "Set the svn:mime-type property (svn propset svn:mime
-type image/png %s)." % self._file_path | |
| 74 self._handle_style_error(0, 'image/png', 5, errorstr) | |
| 75 | |
| OLD | NEW |