aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/update-svn-properties.py
diff options
context:
space:
mode:
Diffstat (limited to 'update-svn-properties.py')
-rwxr-xr-xupdate-svn-properties.py171
1 files changed, 0 insertions, 171 deletions
diff --git a/update-svn-properties.py b/update-svn-properties.py
deleted file mode 100755
index f8d53bf..0000000
--- a/update-svn-properties.py
+++ /dev/null
@@ -1,171 +0,0 @@
1#!/usr/bin/env python
2
3import os, os.path, popen2, re, string, sys
4
5def text(file):
6 return {
7 "svn:eol-style" : "native"
8 }
9
10def script(file):
11 return {
12 "svn:eol-style" : "native",
13 "svn:executable" : "*"
14 }
15
16def executable(file):
17 return {
18 "svn:executable" : "*",
19 "svn:mime-type" : "application/octet-stream"
20 }
21
22def binary(file):
23 return {
24 "svn:mime-type" : "application/octet-stream"
25 }
26
27def is_binary(file):
28 f = open(file)
29 data = f.read()
30 f.close()
31
32 for c in data:
33 if c not in string.printable:
34 return True
35 return False
36
37def binary_or_text(file):
38 if is_binary(file):
39 return binary(file)
40 else:
41 return text(file)
42
43property_map = {
44 ".bat" : script,
45 ".build" : text,
46 ".cfg" : text,
47 ".cgi" : text,
48 ".conf" : text,
49 ".config" : text,
50 ".cs" : text,
51 ".csproj" : text,
52 ".dat" : binary_or_text,
53 ".dll" : binary,
54 ".dylib" : binary,
55 ".example" : text,
56 ".exe" : executable,
57 ".fxcop" : text,
58 ".hgignore" : text,
59 ".ico" : binary,
60 ".include" : text,
61 ".ini" : text,
62 ".j2c" : binary,
63 ".jp2" : binary,
64 ".lsl" : text,
65 ".mdp" : text,
66 ".mds" : text,
67 ".nsi" : text,
68 ".ogg" : binary,
69 ".pdb" : binary,
70 ".php" : script,
71 ".pidb" : binary,
72 ".pl" : script,
73 ".plist" : text,
74 ".pm" : text,
75 ".png" : binary,
76 ".py" : script,
77 ".rb" : script,
78 ".resx" : text,
79 ".settings" : text,
80 ".stetic" : text,
81 ".sh" : script,
82 ".snk" : binary,
83 ".so" : binary,
84 ".sql" : text,
85 ".txt" : text,
86 ".user" : text,
87 ".userprefs" : text,
88 ".usertasks" : text,
89 ".xml" : text,
90 ".xsd" : text
91}
92
93def propset(file, property, value):
94 os.system('svn propset %s "%s" "%s"' % (property, value, file))
95
96def propdel(file, property):
97 os.system('svn propdel %s "%s"' % (property, file))
98
99def propget(file, property):
100 output, input, error = popen2.popen3('svn propget %s "%s"' % (property, file))
101
102 err = error.read()
103 if err != "":
104 output.close()
105 error.close()
106 input.close()
107 return ""
108
109 result = output.read()
110 output.close()
111 error.close()
112 input.close()
113 return result.strip()
114
115def proplist(file):
116 output, input, error = popen2.popen3('svn proplist "%s"' % file)
117
118 err = error.read()
119 if err != "":
120 output.close()
121 error.close()
122 input.close()
123 return None
124
125 result = output.readlines()
126 output.close()
127 error.close()
128 input.close()
129 if len(result) > 0 and re.match("^Properties on .*:$", result[0]) is not None:
130 return [r.strip() for r in result[1:]]
131 else:
132 return ""
133
134def update_file(file, properties, ignorelist):
135 current_props = proplist(file)
136
137 if current_props is None:
138 # svn error occurred -- probably an unversioned file
139 return
140
141 for p in current_props:
142 if p not in ignorelist and not properties.has_key(p):
143 propdel(file, p)
144
145 for p in properties:
146 if p not in current_props or propget(file, p) != properties[p]:
147 propset(file, p, properties[p])
148
149def update(dir, ignorelist):
150 for f in os.listdir(dir):
151 fullpath = os.path.join(dir, f)
152 if os.path.isdir(fullpath):
153 if not os.path.islink(fullpath):
154 update(fullpath, ignorelist)
155 else:
156 extension = os.path.splitext(fullpath)[1].lower()
157 if property_map.has_key(extension):
158 update_file(fullpath, property_map[extension](fullpath), ignorelist)
159 elif extension != "" and proplist(fullpath) is not None:
160 print "Warning: No properties defined for %s files (%s)" % (extension, fullpath)
161
162def main(argv = None):
163 if argv is None:
164 argv = sys.argv
165
166 ignorelist = ("svn:keywords",)
167
168 update(".", ignorelist)
169
170if __name__ == "__main__":
171 sys.exit(main())