Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/svneol.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 5ae390ac6c61 |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
49908
diff
changeset
|
1 #! /usr/bin/env python3 |
|
36907
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
2 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
3 """ |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
4 SVN helper script. |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
5 |
|
36908
3e2b5747038f
Taught svneol to look at .c and .h files too, and
Tim Peters <tim.peters@gmail.com>
parents:
36907
diff
changeset
|
6 Try to set the svn:eol-style property to "native" on every .py, .txt, .c and |
|
3e2b5747038f
Taught svneol to look at .c and .h files too, and
Tim Peters <tim.peters@gmail.com>
parents:
36907
diff
changeset
|
7 .h file in the directory tree rooted at the current directory. |
|
36907
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
8 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
9 Files with the svn:eol-style property already set (to anything) are skipped. |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
10 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
11 svn will itself refuse to set this property on a file that's not under SVN |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
12 control, or that has a binary mime-type property set. This script inherits |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
13 that behavior, and passes on whatever warning message the failing "svn |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
14 propset" command produces. |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
15 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
16 In the Python project, it's safe to invoke this script from the root of |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
17 a checkout. |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
18 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
19 No output is produced for files that are ignored. For a file that gets |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
20 svn:eol-style set, output looks like: |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
21 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
22 property 'svn:eol-style' set on 'Lib\ctypes\__init__.py' |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
23 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
24 For a file not under version control: |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
25 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
26 svn: warning: 'patch-finalizer.txt' is not under version control |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
27 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
28 and for a file with a binary mime-type property: |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
29 |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
30 svn: File 'Lib\test\test_pep263.py' has binary mime type property |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
31 """ |
|
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
32 |
|
36908
3e2b5747038f
Taught svneol to look at .c and .h files too, and
Tim Peters <tim.peters@gmail.com>
parents:
36907
diff
changeset
|
33 import re |
|
36907
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
34 import os |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
35 import sys |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
36 import subprocess |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
37 |
|
36907
69eb6d1b99f5
Simple utility to add svn:eol-style to text files under
Tim Peters <tim.peters@gmail.com>
parents:
diff
changeset
|
38 |
|
47712
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
39 def propfiles(root, fn): |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
40 default = os.path.join(root, ".svn", "props", fn + ".svn-work") |
|
47709
e8df9e4873b4
Merged revisions 64262 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
36918
diff
changeset
|
41 try: |
|
e8df9e4873b4
Merged revisions 64262 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
36918
diff
changeset
|
42 format = int(open(os.path.join(root, ".svn", "format")).read().strip()) |
|
e8df9e4873b4
Merged revisions 64262 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
36918
diff
changeset
|
43 except IOError: |
|
47712
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
44 return [] |
|
49908
ed8adfef26c6
Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47712
diff
changeset
|
45 if format in (8, 9): |
|
ed8adfef26c6
Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47712
diff
changeset
|
46 # In version 8 and 9, committed props are stored in prop-base, local |
|
ed8adfef26c6
Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47712
diff
changeset
|
47 # modifications in props |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
48 return [os.path.join(root, ".svn", "prop-base", fn + ".svn-base"), |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
49 os.path.join(root, ".svn", "props", fn + ".svn-work")] |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
50 raise ValueError("Unknown repository format") |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
51 |
|
47709
e8df9e4873b4
Merged revisions 64262 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
36918
diff
changeset
|
52 |
|
36909
0bf53639014a
Directly read working copy data to obtain list of properties.
Martin v. Löwis <martin@v.loewis.de>
parents:
36908
diff
changeset
|
53 def proplist(root, fn): |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
54 """Return a list of property names for file fn in directory root.""" |
|
36909
0bf53639014a
Directly read working copy data to obtain list of properties.
Martin v. Löwis <martin@v.loewis.de>
parents:
36908
diff
changeset
|
55 result = [] |
|
47712
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
56 for path in propfiles(root, fn): |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
57 try: |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
58 f = open(path) |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
59 except IOError: |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
60 # no properties file: not under version control, |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
61 # or no properties set |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
62 continue |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
63 while True: |
|
47712
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
64 # key-value pairs, of the form |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
65 # K <length> |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
66 # <keyname>NL |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
67 # V length |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
68 # <value>NL |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
69 # END |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
70 line = f.readline() |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
71 if line.startswith("END"): |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
72 break |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
73 assert line.startswith("K ") |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
74 L = int(line.split()[1]) |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
75 key = f.read(L) |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
76 result.append(key) |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
77 f.readline() |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
78 line = f.readline() |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
79 assert line.startswith("V ") |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
80 L = int(line.split()[1]) |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
81 value = f.read(L) |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
82 f.readline() |
|
61e5286d937c
Merged revisions 64265 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47709
diff
changeset
|
83 f.close() |
|
36909
0bf53639014a
Directly read working copy data to obtain list of properties.
Martin v. Löwis <martin@v.loewis.de>
parents:
36908
diff
changeset
|
84 return result |
|
0bf53639014a
Directly read working copy data to obtain list of properties.
Martin v. Löwis <martin@v.loewis.de>
parents:
36908
diff
changeset
|
85 |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
86 |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
87 def set_eol_native(path): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
88 cmd = 'svn propset svn:eol-style native "{}"'.format(path) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
89 propset = subprocess.Popen(cmd, shell=True) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
90 propset.wait() |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
91 |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
92 |
|
36918
6e9b368789df
Deleted the svn_mime-type application/octet-stream from PCBuild/pcbuild.sln.
Thomas Heller <theller@ctypes.org>
parents:
36909
diff
changeset
|
93 possible_text_file = re.compile(r"\.([hc]|py|txt|sln|vcproj)$").search |
|
36908
3e2b5747038f
Taught svneol to look at .c and .h files too, and
Tim Peters <tim.peters@gmail.com>
parents:
36907
diff
changeset
|
94 |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
95 |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
96 def main(): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
97 for arg in sys.argv[1:] or [os.curdir]: |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
98 if os.path.isfile(arg): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
99 root, fn = os.path.split(arg) |
|
36909
0bf53639014a
Directly read working copy data to obtain list of properties.
Martin v. Löwis <martin@v.loewis.de>
parents:
36908
diff
changeset
|
100 if 'svn:eol-style' not in proplist(root, fn): |
|
63872
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
101 set_eol_native(arg) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
102 elif os.path.isdir(arg): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
103 for root, dirs, files in os.walk(arg): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
104 if '.svn' in dirs: |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
105 dirs.remove('.svn') |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
106 for fn in files: |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
107 if possible_text_file(fn): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
108 if 'svn:eol-style' not in proplist(root, fn): |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
109 path = os.path.join(root, fn) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
110 set_eol_native(path) |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
111 |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
112 |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
113 if __name__ == '__main__': |
|
5ae390ac6c61
Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
59522
diff
changeset
|
114 main() |
