summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/svneol.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/scripts/svneol.py')
-rw-r--r--Tools/scripts/svneol.py49
1 files changed, 36 insertions, 13 deletions
diff --git a/Tools/scripts/svneol.py b/Tools/scripts/svneol.py
index 80616a6..8abdd01 100644
--- a/Tools/scripts/svneol.py
+++ b/Tools/scripts/svneol.py
@@ -32,9 +32,12 @@ and for a file with a binary mime-type property:
import re
import os
+import sys
+import subprocess
+
def propfiles(root, fn):
- default = os.path.join(root, ".svn", "props", fn+".svn-work")
+ default = os.path.join(root, ".svn", "props", fn + ".svn-work")
try:
format = int(open(os.path.join(root, ".svn", "format")).read().strip())
except IOError:
@@ -42,12 +45,13 @@ def propfiles(root, fn):
if format in (8, 9):
# In version 8 and 9, committed props are stored in prop-base, local
# modifications in props
- return [os.path.join(root, ".svn", "prop-base", fn+".svn-base"),
- os.path.join(root, ".svn", "props", fn+".svn-work")]
- raise ValueError, "Unknown repository format"
+ return [os.path.join(root, ".svn", "prop-base", fn + ".svn-base"),
+ os.path.join(root, ".svn", "props", fn + ".svn-work")]
+ raise ValueError("Unknown repository format")
+
def proplist(root, fn):
- "Return a list of property names for file fn in directory root"
+ """Return a list of property names for file fn in directory root."""
result = []
for path in propfiles(root, fn):
try:
@@ -56,7 +60,7 @@ def proplist(root, fn):
# no properties file: not under version control,
# or no properties set
continue
- while 1:
+ while True:
# key-value pairs, of the form
# K <length>
# <keyname>NL
@@ -79,13 +83,32 @@ def proplist(root, fn):
f.close()
return result
+
+def set_eol_native(path):
+ cmd = 'svn propset svn:eol-style native "{}"'.format(path)
+ propset = subprocess.Popen(cmd, shell=True)
+ propset.wait()
+
+
possible_text_file = re.compile(r"\.([hc]|py|txt|sln|vcproj)$").search
-for root, dirs, files in os.walk('.'):
- if '.svn' in dirs:
- dirs.remove('.svn')
- for fn in files:
- if possible_text_file(fn):
+
+def main():
+ for arg in sys.argv[1:] or [os.curdir]:
+ if os.path.isfile(arg):
+ root, fn = os.path.split(arg)
if 'svn:eol-style' not in proplist(root, fn):
- path = os.path.join(root, fn)
- os.system('svn propset svn:eol-style native "%s"' % path)
+ set_eol_native(arg)
+ elif os.path.isdir(arg):
+ for root, dirs, files in os.walk(arg):
+ if '.svn' in dirs:
+ dirs.remove('.svn')
+ for fn in files:
+ if possible_text_file(fn):
+ if 'svn:eol-style' not in proplist(root, fn):
+ path = os.path.join(root, fn)
+ set_eol_native(path)
+
+
+if __name__ == '__main__':
+ main()