Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/lfcr.py @ 83447:678564fc0962 3.3
#17789: test_random now works with unittest test discovery. Patch by Zachary Ware.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 19 Apr 2013 05:45:27 +0300 |
| parents | 47ffb957921d |
| children |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
42427
diff
changeset
|
1 #! /usr/bin/env python3 |
|
9099
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 "Replace LF with CRLF in argument files. Print names of changed files." |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
| 11763 | 5 import sys, re, os |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
6 |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
7 def main(): |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
8 for filename in sys.argv[1:]: |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
9 if os.path.isdir(filename): |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
33074
diff
changeset
|
10 print(filename, "Directory!") |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
11 continue |
|
71840
47ffb957921d
Update crlf and lfcr scripts for 3.x bytes semantics (#12032).
Éric Araujo <merwok@netwok.org>
parents:
59522
diff
changeset
|
12 with open(filename, "rb") as f: |
|
47ffb957921d
Update crlf and lfcr scripts for 3.x bytes semantics (#12032).
Éric Araujo <merwok@netwok.org>
parents:
59522
diff
changeset
|
13 data = f.read() |
|
47ffb957921d
Update crlf and lfcr scripts for 3.x bytes semantics (#12032).
Éric Araujo <merwok@netwok.org>
parents:
59522
diff
changeset
|
14 if b'\0' in data: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
33074
diff
changeset
|
15 print(filename, "Binary!") |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
16 continue |
|
71840
47ffb957921d
Update crlf and lfcr scripts for 3.x bytes semantics (#12032).
Éric Araujo <merwok@netwok.org>
parents:
59522
diff
changeset
|
17 newdata = re.sub(b"\r?\n", b"\r\n", data) |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
18 if newdata != data: |
|
42427
46625e6122e9
Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents:
33074
diff
changeset
|
19 print(filename) |
|
71840
47ffb957921d
Update crlf and lfcr scripts for 3.x bytes semantics (#12032).
Éric Araujo <merwok@netwok.org>
parents:
59522
diff
changeset
|
20 with open(filename, "wb") as f: |
|
47ffb957921d
Update crlf and lfcr scripts for 3.x bytes semantics (#12032).
Éric Araujo <merwok@netwok.org>
parents:
59522
diff
changeset
|
21 f.write(newdata) |
|
33074
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
22 |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
23 if __name__ == '__main__': |
|
981fff7363b9
[Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents:
29102
diff
changeset
|
24 main() |
