checksvnconfigfile.py 2.7 KB

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