Tim Peters | d87f81f | 2006-03-09 01:42:24 +0000 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | """ |
| 4 | SVN helper script. |
| 5 | |
| 6 | Try to set the svn:eol-style property to "native" on every .py and .txt file |
| 7 | in the directory tree rooted at the current directory. |
| 8 | |
| 9 | Files with the svn:eol-style property already set (to anything) are skipped. |
| 10 | |
| 11 | svn will itself refuse to set this property on a file that's not under SVN |
| 12 | control, or that has a binary mime-type property set. This script inherits |
| 13 | that behavior, and passes on whatever warning message the failing "svn |
| 14 | propset" command produces. |
| 15 | |
| 16 | In the Python project, it's safe to invoke this script from the root of |
| 17 | a checkout. |
| 18 | |
| 19 | No output is produced for files that are ignored. For a file that gets |
| 20 | svn:eol-style set, output looks like: |
| 21 | |
| 22 | property 'svn:eol-style' set on 'Lib\ctypes\__init__.py' |
| 23 | |
| 24 | For a file not under version control: |
| 25 | |
| 26 | svn: warning: 'patch-finalizer.txt' is not under version control |
| 27 | |
| 28 | and 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 | TODO: This is slow, and especially on Windows, because it invokes a new svn |
| 33 | command-line operation for every .py and .txt file. |
| 34 | """ |
| 35 | |
| 36 | import os |
| 37 | |
| 38 | for root, dirs, files in os.walk('.'): |
| 39 | if '.svn' in dirs: |
| 40 | dirs.remove('.svn') |
| 41 | for fn in files: |
| 42 | if fn.endswith('.py') or fn.endswith('.txt'): |
| 43 | path = os.path.join(root, fn) |
| 44 | p = os.popen('svn proplist "%s"' % path) |
| 45 | guts = p.read() |
| 46 | p.close() |
| 47 | if 'eol-style' not in guts: |
| 48 | os.system('svn propset svn:eol-style native "%s"' % path) |