Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/lfcr.py @ 9281:809dcc1bbc21 legacy-trunk
Added #! line
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 07 Oct 1998 14:46:09 +0000 |
| parents | f2396d43056b |
| children | 9876a64c181a |
| rev | line source |
|---|---|
|
9099
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
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 |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 import sys, regsub, os |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 for file in sys.argv[1:]: |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 if os.path.isdir(file): |
| 9102 | 8 print file, "Directory!" |
| 9 continue | |
|
9099
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 data = open(file, "rb").read() |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 if '\0' in data: |
| 9102 | 12 print file, "Binary!" |
| 13 continue | |
|
9099
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 newdata = regsub.gsub("\r?\n", "\r\n", data) |
|
728bbeb9e4f9
Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 if newdata != data: |
| 9102 | 16 print file |
| 17 f = open(file, "wb") | |
| 18 f.write(newdata) | |
| 19 f.close() |
