Home | History | Annotate | Download | only in common
      1 # Copyright (C) 2012 Balazs Ankes (bank (at] 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 # This file is used by:
     25 # webkitpy/tool/steps/addsvnmimetypeforpng.py
     26 # webkitpy/style/checkers/png.py
     27 
     28 import os
     29 import re
     30 
     31 
     32 def check(host, fs):
     33     """
     34     check the svn config file
     35     return with three logical value:
     36     is svn config file missing, is auto-props missing, is the svn:mime-type for png missing
     37     """
     38 
     39     cfg_file_path = config_file_path(host, fs)
     40 
     41     try:
     42         config_file = fs.read_text_file(cfg_file_path)
     43     except IOError:
     44         return (True, True, True)
     45 
     46     errorcode_autoprop = not re.search("^\s*enable-auto-props\s*=\s*yes", config_file, re.MULTILINE)
     47     errorcode_png = not re.search("^\s*\*\.png\s*=\s*svn:mime-type=image/png", config_file, re.MULTILINE)
     48 
     49     return (False, errorcode_autoprop, errorcode_png)
     50 
     51 
     52 def config_file_path(host, fs):
     53     if host.platform.is_win():
     54         config_file_path = fs.join(os.environ['APPDATA'], "Subversion", "config")
     55     else:
     56         config_file_path = fs.join(fs.expanduser("~"), ".subversion", "config")
     57     return config_file_path
     58 
     59 
     60 def errorstr_autoprop(config_file_path):
     61     return 'Have to enable auto props in the subversion config file (%s "enable-auto-props = yes"). ' % config_file_path
     62 
     63 
     64 def errorstr_png(config_file_path):
     65     return 'Have to set the svn:mime-type in the subversion config file (%s "*.png = svn:mime-type=image/png").' % config_file_path
     66