annotate Tools/scripts/crlf.py @ 17322:bd110eadc19a legacy-trunk

One-liner critical fix from Jim Fulton: Eric's string-method crusade got the order backwards in a line (for .find()).
author Tim Peters <tim.peters@gmail.com>
date Thu, 05 Apr 2001 22:26:23 +0000
parents 9876a64c181a
children d37f1378d8b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
11763
9876a64c181a Patch by Gerrit Holl:
Guido van Rossum <guido@python.org>
parents: 9100
diff changeset
5 import sys, re, os
9100
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 for file in sys.argv[1:]:
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 if os.path.isdir(file):
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 print file, "Directory!"
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 continue
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 data = open(file, "rb").read()
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 if '\0' in data:
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 print file, "Binary!"
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 continue
11763
9876a64c181a Patch by Gerrit Holl:
Guido van Rossum <guido@python.org>
parents: 9100
diff changeset
14 newdata = re.sub("\r\n", "\n", data)
9100
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 if newdata != data:
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 print file
687b66e653d6 Utility to replace CRLF with LF in argument files.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 f = open(file, "wb")
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()