Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/crlf.py @ 32527:0da660e05e69 legacy-trunk
"#if WITH_THREAD" is incorrect; must be #ifdef instead; WITH_THREAD
isn't always set to an integer value when it's defined.
| author | Tim Peters <tim.peters@gmail.com> |
|---|---|
| date | Wed, 07 Jul 2004 20:42:07 +0000 |
| parents | 5ce629642155 |
| children | 981fff7363b9 |
| rev | line source |
|---|---|
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 "Replace CRLF with LF in argument files. Print names of changed files." |
|
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
26199
d37f1378d8b8
Tim wins a bet. Don't use re.
Guido van Rossum <guido@python.org>
parents:
11763
diff
changeset
|
5 import sys, os |
|
29099
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
6 for filename in sys.argv[1:]: |
|
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
7 if os.path.isdir(filename): |
|
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
8 print filename, "Directory!" |
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 continue |
|
29099
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
10 data = open(filename, "rb").read() |
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 if '\0' in data: |
|
29099
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
12 print filename, "Binary!" |
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 continue |
|
26199
d37f1378d8b8
Tim wins a bet. Don't use re.
Guido van Rossum <guido@python.org>
parents:
11763
diff
changeset
|
14 newdata = data.replace("\r\n", "\n") |
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 if newdata != data: |
|
29099
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
16 print filename |
|
5ce629642155
[Bug #724767] crlf.py uses the variable name file, which it shouldn't anymore.
Andrew M. Kuchling <amk@amk.ca>
parents:
26199
diff
changeset
|
17 f = open(filename, "wb") |
|
9100
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 f.write(newdata) |
|
687b66e653d6
Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 f.close() |
