2008-01-26 10:34:49 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os, os.path, popen2, re, string, sys
|
|
|
|
|
2008-05-06 22:14:15 +00:00
|
|
|
def text(file):
|
2008-01-26 10:34:49 +00:00
|
|
|
return {
|
|
|
|
"svn:eol-style" : "native"
|
|
|
|
}
|
|
|
|
|
|
|
|
def script(file):
|
|
|
|
return {
|
|
|
|
"svn:eol-style" : "native",
|
|
|
|
"svn:executable" : "*"
|
|
|
|
}
|
|
|
|
|
|
|
|
def executable(file):
|
|
|
|
return {
|
|
|
|
"svn:executable" : "*",
|
|
|
|
"svn:mime-type" : "application/octet-stream"
|
|
|
|
}
|
|
|
|
|
|
|
|
def binary(file):
|
|
|
|
return {
|
|
|
|
"svn:mime-type" : "application/octet-stream"
|
|
|
|
}
|
|
|
|
|
|
|
|
def is_binary(file):
|
|
|
|
f = open(file)
|
|
|
|
data = f.read()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
for c in data:
|
|
|
|
if c not in string.printable:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def binary_or_text(file):
|
|
|
|
if is_binary(file):
|
|
|
|
return binary(file)
|
|
|
|
else:
|
2008-05-06 22:14:15 +00:00
|
|
|
return text(file)
|
2008-01-26 10:34:49 +00:00
|
|
|
|
|
|
|
property_map = {
|
|
|
|
".bat" : script,
|
2008-05-06 22:14:15 +00:00
|
|
|
".build" : text,
|
|
|
|
".cfg" : text,
|
|
|
|
".cgi" : text,
|
2008-06-01 03:01:33 +00:00
|
|
|
".conf" : text,
|
2008-05-06 22:14:15 +00:00
|
|
|
".config" : text,
|
|
|
|
".cs" : text,
|
|
|
|
".csproj" : text,
|
2008-01-26 10:34:49 +00:00
|
|
|
".dat" : binary_or_text,
|
|
|
|
".dll" : binary,
|
|
|
|
".dylib" : binary,
|
2008-05-06 22:14:15 +00:00
|
|
|
".example" : text,
|
2008-01-26 10:34:49 +00:00
|
|
|
".exe" : executable,
|
2008-05-06 22:14:15 +00:00
|
|
|
".fxcop" : text,
|
|
|
|
".hgignore" : text,
|
2008-01-26 10:34:49 +00:00
|
|
|
".ico" : binary,
|
2008-05-06 22:14:15 +00:00
|
|
|
".include" : text,
|
|
|
|
".ini" : text,
|
2008-01-26 10:34:49 +00:00
|
|
|
".j2c" : binary,
|
|
|
|
".jp2" : binary,
|
2008-05-06 22:14:15 +00:00
|
|
|
".lsl" : text,
|
|
|
|
".mdp" : text,
|
|
|
|
".mds" : text,
|
|
|
|
".nsi" : text,
|
2008-02-02 07:13:37 +00:00
|
|
|
".pdb" : binary,
|
2008-01-26 10:34:49 +00:00
|
|
|
".php" : script,
|
|
|
|
".pidb" : binary,
|
|
|
|
".pl" : script,
|
2008-05-06 22:14:15 +00:00
|
|
|
".plist" : text,
|
|
|
|
".pm" : text,
|
2008-01-26 10:34:49 +00:00
|
|
|
".png" : binary,
|
|
|
|
".py" : script,
|
|
|
|
".rb" : script,
|
2008-05-06 22:14:15 +00:00
|
|
|
".resx" : text,
|
|
|
|
".settings" : text,
|
|
|
|
".stetic" : text,
|
2008-01-26 10:34:49 +00:00
|
|
|
".sh" : script,
|
|
|
|
".snk" : binary,
|
|
|
|
".so" : binary,
|
2008-05-06 22:14:15 +00:00
|
|
|
".sql" : text,
|
|
|
|
".txt" : text,
|
|
|
|
".user" : text,
|
|
|
|
".userprefs" : text,
|
|
|
|
".usertasks" : text,
|
|
|
|
".xml" : text,
|
|
|
|
".xsd" : text
|
2008-01-26 10:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def propset(file, property, value):
|
|
|
|
os.system('svn propset %s "%s" "%s"' % (property, value, file))
|
|
|
|
|
|
|
|
def propdel(file, property):
|
|
|
|
os.system('svn propdel %s "%s"' % (property, file))
|
|
|
|
|
|
|
|
def propget(file, property):
|
|
|
|
output, input, error = popen2.popen3('svn propget %s "%s"' % (property, file))
|
|
|
|
|
|
|
|
err = error.read()
|
|
|
|
if err != "":
|
|
|
|
output.close()
|
|
|
|
error.close()
|
|
|
|
input.close()
|
|
|
|
return ""
|
|
|
|
|
|
|
|
result = output.read()
|
|
|
|
output.close()
|
|
|
|
error.close()
|
|
|
|
input.close()
|
|
|
|
return result.strip()
|
|
|
|
|
|
|
|
def proplist(file):
|
|
|
|
output, input, error = popen2.popen3('svn proplist "%s"' % file)
|
|
|
|
|
|
|
|
err = error.read()
|
|
|
|
if err != "":
|
|
|
|
output.close()
|
|
|
|
error.close()
|
|
|
|
input.close()
|
|
|
|
return None
|
|
|
|
|
|
|
|
result = output.readlines()
|
|
|
|
output.close()
|
|
|
|
error.close()
|
|
|
|
input.close()
|
|
|
|
if len(result) > 0 and re.match("^Properties on .*:$", result[0]) is not None:
|
|
|
|
return [r.strip() for r in result[1:]]
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
2008-05-06 22:14:15 +00:00
|
|
|
def update_file(file, properties, ignorelist):
|
2008-01-26 10:34:49 +00:00
|
|
|
current_props = proplist(file)
|
|
|
|
|
|
|
|
if current_props is None:
|
|
|
|
# svn error occurred -- probably an unversioned file
|
|
|
|
return
|
|
|
|
|
|
|
|
for p in current_props:
|
2008-05-06 22:14:15 +00:00
|
|
|
if p not in ignorelist and not properties.has_key(p):
|
2008-01-26 10:34:49 +00:00
|
|
|
propdel(file, p)
|
|
|
|
|
|
|
|
for p in properties:
|
|
|
|
if p not in current_props or propget(file, p) != properties[p]:
|
|
|
|
propset(file, p, properties[p])
|
|
|
|
|
2008-05-06 22:14:15 +00:00
|
|
|
def update(dir, ignorelist):
|
2008-01-26 10:34:49 +00:00
|
|
|
for f in os.listdir(dir):
|
|
|
|
fullpath = os.path.join(dir, f)
|
|
|
|
if os.path.isdir(fullpath):
|
|
|
|
if not os.path.islink(fullpath):
|
2008-05-06 22:14:15 +00:00
|
|
|
update(fullpath, ignorelist)
|
2008-01-26 10:34:49 +00:00
|
|
|
else:
|
|
|
|
extension = os.path.splitext(fullpath)[1].lower()
|
|
|
|
if property_map.has_key(extension):
|
2008-05-06 22:14:15 +00:00
|
|
|
update_file(fullpath, property_map[extension](fullpath), ignorelist)
|
2008-01-26 10:34:49 +00:00
|
|
|
elif extension != "" and proplist(fullpath) is not None:
|
|
|
|
print "Warning: No properties defined for %s files (%s)" % (extension, fullpath)
|
|
|
|
|
|
|
|
def main(argv = None):
|
|
|
|
if argv is None:
|
|
|
|
argv = sys.argv
|
|
|
|
|
2008-05-06 22:14:15 +00:00
|
|
|
ignorelist = ("svn:keywords",)
|
|
|
|
|
|
|
|
update(".", ignorelist)
|
2008-01-26 10:34:49 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|