forked from louisepb/TexGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetEOLProps.py
More file actions
42 lines (40 loc) · 1.67 KB
/
SetEOLProps.py
File metadata and controls
42 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pysvn, os.path
def ConvertLineEndings(fileName):
print "Converting line endings for file:", fileName
file = open(fileName)
lines = file.readlines()
file.close()
# Convert to '\n' line feeds
for i in range(len(lines)):
lines[i] = lines[i].replace('\r\n', '\n')
lines[i] = lines[i].replace('\r', '\n')
file = open(fileName, 'w')
file.writelines(lines)
file.close()
# Set the Subversion 'svn:eol-style' property for all text files to 'native'
# This will make sure there are no problems with developing code between
# linux and windows systems
textFileExtensions = ['.txt', '.py', '.cpp', '.c', '.h', '.hpp', '.cxx', '.hxx', '.in',
'.dot', '.ini', '.nsi', '.tg3', '.i', '.cfl', '.pth']
client = pysvn.Client()
changes = client.status('.')
for f in changes:
if f.is_versioned:
root, ext = os.path.splitext(f.path)
if ext in textFileExtensions:
prop_list = client.propget('svn:eol-style', f.path)
key = f.path.replace('\\', '/')
if key in prop_list and prop_list[key] == 'native':
pass # Property already set
else:
print "Setting 'svn:eol-style' property to 'native' for:", f.path
try:
client.propset('svn:eol-style', 'native', f.path)
except pysvn.ClientError, e:
if 'inconsistent newlines' in str(e):
ConvertLineEndings(f.path)
client.propset('svn:eol-style', 'native', f.path)
else:
raise
else:
print 'No end of line conversion for:', f.path