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