source: vendor/python/2.5/Tools/scripts/svneol.py

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.2 KB
Line 
1#! /usr/bin/env python
2
3"""
4SVN helper script.
5
6Try 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.
8
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"""
32
33import re
34import os
35
36def proplist(root, fn):
37 "Return a list of property names for file fn in directory root"
38 path = os.path.join(root, ".svn", "props", fn+".svn-work")
39 try:
40 f = open(path)
41 except IOError:
42 # no properties file: not under version control
43 return []
44 result = []
45 while 1:
46 # key-value pairs, of the form
47 # K <length>
48 # <keyname>NL
49 # V length
50 # <value>NL
51 # END
52 line = f.readline()
53 if line.startswith("END"):
54 break
55 assert line.startswith("K ")
56 L = int(line.split()[1])
57 key = f.read(L)
58 result.append(key)
59 f.readline()
60 line = f.readline()
61 assert line.startswith("V ")
62 L = int(line.split()[1])
63 value = f.read(L)
64 f.readline()
65 f.close()
66 return result
67
68possible_text_file = re.compile(r"\.([hc]|py|txt|sln|vcproj)$").search
69
70for root, dirs, files in os.walk('.'):
71 if '.svn' in dirs:
72 dirs.remove('.svn')
73 for fn in files:
74 if possible_text_file(fn):
75 if 'svn:eol-style' not in proplist(root, fn):
76 path = os.path.join(root, fn)
77 os.system('svn propset svn:eol-style native "%s"' % path)
Note: See TracBrowser for help on using the repository browser.