Commit cb32645e authored by ossy@webkit.org's avatar ossy@webkit.org
Browse files

webkit-patch land should automatically add svn:mime-type for .png files

https://bugs.webkit.org/show_bug.cgi?id=75825

Patch by Balazs Ankes <bank@inf.u-szeged.hu> on 2012-07-11
Reviewed by Dirk Pranke.

Refactor the png.py to avoid code duplication.

* Scripts/webkitpy/common/checksvnconfigfile.py: Added.
(check):
(config_file_path):
(errorstr_autoprop):
(errorstr_png):
* Scripts/webkitpy/style/checkers/png.py:
(PNGChecker.check):
* Scripts/webkitpy/tool/commands/download.py:
(Land):
* Scripts/webkitpy/tool/steps/__init__.py:
* Scripts/webkitpy/tool/steps/addsvnmimetypeforpng.py: Added.
(AddSvnMimetypeForPng):
(AddSvnMimetypeForPng.__init__):
(AddSvnMimetypeForPng.run):
(AddSvnMimetypeForPng._check_pngs):
* Scripts/webkitpy/tool/steps/addsvnmimetypeforpng_unittest.py: Added.
(MockSCMDetector):
(MockSCMDetector.__init__):
(MockSCMDetector.display_name):
(AddSvnMimetypeForPngTest):
(AddSvnMimetypeForPngTest.test_run):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@122311 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fff39fe6
2012-07-11 Balazs Ankes <bank@inf.u-szeged.hu>
webkit-patch land should automatically add svn:mime-type for .png files
https://bugs.webkit.org/show_bug.cgi?id=75825
Reviewed by Dirk Pranke.
Refactor the png.py to avoid code duplication.
* Scripts/webkitpy/common/checksvnconfigfile.py: Added.
(check):
(config_file_path):
(errorstr_autoprop):
(errorstr_png):
* Scripts/webkitpy/style/checkers/png.py:
(PNGChecker.check):
* Scripts/webkitpy/tool/commands/download.py:
(Land):
* Scripts/webkitpy/tool/steps/__init__.py:
* Scripts/webkitpy/tool/steps/addsvnmimetypeforpng.py: Added.
(AddSvnMimetypeForPng):
(AddSvnMimetypeForPng.__init__):
(AddSvnMimetypeForPng.run):
(AddSvnMimetypeForPng._check_pngs):
* Scripts/webkitpy/tool/steps/addsvnmimetypeforpng_unittest.py: Added.
(MockSCMDetector):
(MockSCMDetector.__init__):
(MockSCMDetector.display_name):
(AddSvnMimetypeForPngTest):
(AddSvnMimetypeForPngTest.test_run):
2012-07-11 Hayato Ito <hayato@chromium.org>
Unreviewed gardening.
......
# Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This file is used by:
# webkitpy/tool/steps/addsvnmimetypeforpng.py
# webkitpy/style/checkers/png.py
import os
import re
def check(host, fs):
"""
check the svn config file
return with three logical value:
is svn config file missing, is auto-props missing, is the svn:mime-type for png missing
"""
cfg_file_path = config_file_path(host, fs)
try:
config_file = fs.read_text_file(cfg_file_path)
except IOError:
return (True, True, True)
errorcode_autoprop = not re.search("^\s*enable-auto-props\s*=\s*yes", config_file, re.MULTILINE)
errorcode_png = not re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", config_file, re.MULTILINE)
return (False, errorcode_autoprop, errorcode_png)
def config_file_path(host, fs):
if host.platform.is_win():
config_file_path = fs.join(os.environ['APPDATA'], "Subversion", "config")
else:
config_file_path = fs.join(fs.expanduser("~"), ".subversion", "config")
return config_file_path
def errorstr_autoprop(config_file_path):
return 'Have to enable auto props in the subversion config file (%s "enable-auto-props = yes"). ' % config_file_path
def errorstr_png(config_file_path):
return 'Have to set the svn:mime-type in the subversion config file (%s "*.png = svn:mime-type=image/png").' % config_file_path
......@@ -27,6 +27,7 @@
import os
import re
from webkitpy.common import checksvnconfigfile
from webkitpy.common import read_checksum_from_png
from webkitpy.common.system.systemhost import SystemHost
from webkitpy.common.checkout.scm.detection import SCMDetector
......@@ -54,49 +55,21 @@ class PNGChecker(object):
self._handle_style_error(0, 'image/png', 5, "Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.")
if detection == "git":
config_file_path = self._config_file_path()
there_is_enable_line = False
there_is_png_line = False
try:
config_file = self._fs.read_text_file(config_file_path)
except IOError:
errorstr = "There is no " + config_file_path
self._handle_style_error(0, 'image/png', 5, errorstr)
return
errorstr_autoprop = "Have to enable auto props in the subversion config file (" + config_file_path + " \"enable-auto-props = yes\"). "
errorstr_png = "Have to set the svn:mime-type in the subversion config file (" + config_file_path + " \"*.png = svn:mime-type=image/png\")."
for line in config_file.split('\n'):
if not there_is_enable_line:
match = re.search("^\s*enable-auto-props\s*=\s*yes", line)
if match:
there_is_enable_line = True
errorstr_autoprop = ""
continue
if not there_is_png_line:
match = re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", line)
if match:
there_is_png_line = True
errorstr_png = ""
continue
errorstr = errorstr_autoprop + errorstr_png
if errorstr:
self._handle_style_error(0, 'image/png', 5, errorstr)
(file_missing, autoprop_missing, png_missing) = checksvnconfigfile.check(self._host, self._fs)
config_file_path = checksvnconfigfile.config_file_path(self._host, self._fs)
if file_missing:
self._handle_style_error(0, 'image/png', 5, "There is no SVN config file. (%s)" % config_file_path)
elif autoprop_missing and png_missing:
self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file_path))
elif autoprop_missing:
self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_autoprop(config_file_path))
elif png_missing:
self._handle_style_error(0, 'image/png', 5, checksvnconfigfile.errorstr_png(config_file_path))
elif detection == "svn":
prop_get = self._detector.propget("svn:mime-type", self._file_path)
if prop_get != "image/png":
errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png " + self._file_path + ")."
errorstr = "Set the svn:mime-type property (svn propset svn:mime-type image/png %s)." % self._file_path
self._handle_style_error(0, 'image/png', 5, errorstr)
def _config_file_path(self):
config_file = ""
if self._host.platform.is_win():
config_file_path = self._fs.join(os.environ['APPDATA'], "Subversion\config")
else:
config_file_path = self._fs.join(self._fs.expanduser("~"), ".subversion/config")
return config_file_path
......@@ -90,6 +90,7 @@ class Land(AbstractSequencedCommand):
argument_names = "[BUGID]"
show_in_main_help = True
steps = [
steps.AddSvnMimetypeForPng,
steps.UpdateChangeLogsWithReviewer,
steps.ValidateReviewer,
steps.ValidateChangeLogs, # We do this after UpdateChangeLogsWithReviewer to avoid not having to cache the diff twice.
......
......@@ -27,6 +27,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# FIXME: Is this the right way to do this?
from webkitpy.tool.steps.addsvnmimetypeforpng import AddSvnMimetypeForPng
from webkitpy.tool.steps.applypatch import ApplyPatch
from webkitpy.tool.steps.applypatchwithlocalcommit import ApplyPatchWithLocalCommit
from webkitpy.tool.steps.applywatchlist import ApplyWatchList
......
# Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from webkitpy.tool.steps.abstractstep import AbstractStep
from webkitpy.common import checksvnconfigfile
from webkitpy.common.system.deprecated_logging import log
from webkitpy.common.checkout.scm.detection import SCMDetector
from webkitpy.common.system.systemhost import SystemHost
class AddSvnMimetypeForPng(AbstractStep):
def __init__(self, tool, options, host=None, scm=None):
self._tool = tool
self._options = options
self._host = host or SystemHost()
self._fs = self._host.filesystem
self._detector = scm or SCMDetector(self._fs, self._host.executive).detect_scm_system(self._fs.getcwd())
def run(self, state):
png_files = self._check_pngs(self._changed_files(state))
if png_files:
detection = self._detector.display_name()
if detection == "git":
(file_missing, autoprop_missing, png_missing) = checksvnconfigfile.check(self._host, self._fs)
config_file_path = checksvnconfigfile.config_file_path(self._host, self._fs)
if file_missing:
log("There is no SVN config file. The svn:mime-type of pngs won't set.")
if not self._tool.user.confirm("Are you sure you want to continue?", default="n"):
self._exit(1)
elif autoprop_missing and png_missing:
log(checksvnconfigfile.errorstr_autoprop(config_file_path) + checksvnconfigfile.errorstr_png(config_file_path))
if not self._tool.user.confirm("Do you want to continue?", default="n"):
self._exit(1)
elif autoprop_missing:
log(checksvnconfigfile.errorstr_autoprop(config_file_path))
if not self._tool.user.confirm("Do you want to continue?", default="n"):
self._exit(1)
elif png_missing:
log(checksvnconfigfile.errorstr_png(config_file_path))
if not self._tool.user.confirm("Do you want to continue?", default="n"):
self._exit(1)
elif detection == "svn":
for filename in png_files:
if self._detector.exists(filename) and self._detector.propget('svn:mime-type', filename) != 'image/png':
print "Adding image/png mime-type to %s" % filename
self._detector.propset('svn:mime-type', 'image/png', filename)
def _check_pngs(self, changed_files):
png_files = []
for filename in changed_files:
if filename.endswith('.png'):
png_files.append(filename)
return png_files
# Copyright (C) 2012 Balazs Ankes (bank@inf.u-szeged.hu) University of Szeged
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest
from webkitpy.tool.steps.addsvnmimetypeforpng import AddSvnMimetypeForPng
from webkitpy.common.system.filesystem_mock import MockFileSystem
from webkitpy.tool.mocktool import MockOptions, MockTool
from webkitpy.common.system.systemhost_mock import MockSystemHost
from webkitpy.common.system.outputcapture import OutputCapture
class MockSCMDetector(object):
def __init__(self, scm):
self._scm = scm
def display_name(self):
return self._scm
class AddSvnMimetypeForPngTest(unittest.TestCase):
def test_run(self):
capture = OutputCapture()
options = MockOptions(git_commit='MOCK git commit')
files = {'/Users/mock/.subversion/config': 'enable-auto-props = yes\n*.png = svn:mime-type=image/png'}
fs = MockFileSystem(files)
scm = MockSCMDetector('git')
step = AddSvnMimetypeForPng(MockTool(), options, MockSystemHost(os_name='linux', filesystem=fs), scm)
state = {
"changed_files": ["test.png", "test.txt"],
}
try:
capture.assert_outputs(self, step.run, [state])
except SystemExit, e:
self.assertEquals(e.code, 1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment