blob: 9bab1750e020da24ab7ae7214fa14d622f0fc2a8 [file] [log] [blame]
Tim Petersd87f81f2006-03-09 01:42:24 +00001#! /usr/bin/env python
2
3"""
4SVN helper script.
5
Tim Peters84457af2006-03-09 01:59:27 +00006Try to set the svn:eol-style property to "native" on every .py, .txt, .c and
7.h file in the directory tree rooted at the current directory.
Tim Petersd87f81f2006-03-09 01:42:24 +00008
9Files with the svn:eol-style property already set (to anything) are skipped.
10
11svn will itself refuse to set this property on a file that's not under SVN
12control, or that has a binary mime-type property set. This script inherits
13that behavior, and passes on whatever warning message the failing "svn
14propset" command produces.
15
16In the Python project, it's safe to invoke this script from the root of
17a checkout.
18
19No output is produced for files that are ignored. For a file that gets
20svn:eol-style set, output looks like:
21
22 property 'svn:eol-style' set on 'Lib\ctypes\__init__.py'
23
24For a file not under version control:
25
26 svn: warning: 'patch-finalizer.txt' is not under version control
27
28and for a file with a binary mime-type property:
29
30 svn: File 'Lib\test\test_pep263.py' has binary mime type property
31
32TODO: This is slow, and especially on Windows, because it invokes a new svn
Tim Peters84457af2006-03-09 01:59:27 +000033command-line operation for every file with the right extension.
Tim Petersd87f81f2006-03-09 01:42:24 +000034"""
35
Tim Peters84457af2006-03-09 01:59:27 +000036import re
Tim Petersd87f81f2006-03-09 01:42:24 +000037import os
38
Tim Peters84457af2006-03-09 01:59:27 +000039possible_text_file = re.compile(r"\.([hc]|py|txt)$").search
40
Tim Petersd87f81f2006-03-09 01:42:24 +000041for root, dirs, files in os.walk('.'):
42 if '.svn' in dirs:
43 dirs.remove('.svn')
44 for fn in files:
Tim Peters84457af2006-03-09 01:59:27 +000045 if possible_text_file(fn):
Tim Petersd87f81f2006-03-09 01:42:24 +000046 path = os.path.join(root, fn)
47 p = os.popen('svn proplist "%s"' % path)
48 guts = p.read()
49 p.close()
50 if 'eol-style' not in guts:
51 os.system('svn propset svn:eol-style native "%s"' % path)