annotate Tools/scripts/lfcr.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 7a1ae475e0da
children 981fff7363b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
11763
9876a64c181a Patch by Gerrit Holl:
Guido van Rossum <guido@python.org>
parents: 9102
diff changeset
5 import sys, re, os
29102
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
6 for filename in sys.argv[1:]:
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
7 if os.path.isdir(filename):
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
8 print filename, "Directory!"
9102
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
9 continue
29102
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
10 data = open(filename, "rb").read()
9099
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 if '\0' in data:
29102
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
12 print filename, "Binary!"
9102
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
13 continue
11763
9876a64c181a Patch by Gerrit Holl:
Guido van Rossum <guido@python.org>
parents: 9102
diff changeset
14 newdata = re.sub("\r?\n", "\r\n", data)
9099
728bbeb9e4f9 Utility to replace LF with CRLF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 if newdata != data:
29102
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
16 print filename
7a1ae475e0da [Bug #724767] Avoid use of 'file' as a variable name
Andrew M. Kuchling <amk@amk.ca>
parents: 11763
diff changeset
17 f = open(filename, "wb")
9102
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
18 f.write(newdata)
f2396d43056b nannified.
Guido van Rossum <guido@python.org>
parents: 9099
diff changeset
19 f.close()