Mercurial > cpython-lru_cache-weakref
annotate Mac/scripts/crlf.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | fa8bbd09f2e6 |
| children |
| rev | line source |
|---|---|
| 1615 | 1 #! /usr/local/bin/python |
| 2 | |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1615
diff
changeset
|
3 # Replace \r by \n -- useful after transferring files from the Mac... |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1615
diff
changeset
|
4 # Run this on UNIX. |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1615
diff
changeset
|
5 # Usage: crlf.py file ... |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1615
diff
changeset
|
6 |
| 1615 | 7 import sys |
| 8 import os | |
| 9 import string | |
| 10 | |
| 11 def main(): | |
| 12 args = sys.argv[1:] | |
| 13 if not args: | |
|
1795
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1615
diff
changeset
|
14 print 'usage:', sys.argv[0], 'file ...' |
|
fa8bbd09f2e6
Updates for THINK C 6.0. Moved the necessary UNIX emulation routines here.
Guido van Rossum <guido@python.org>
parents:
1615
diff
changeset
|
15 sys.exit(2) |
| 1615 | 16 for file in args: |
| 17 print file, '...' | |
| 18 data = open(file, 'r').read() | |
| 19 lines = string.splitfields(data, '\r') | |
| 20 newdata = string.joinfields(lines, '\n') | |
| 21 if newdata != data: | |
| 22 print 'rewriting...' | |
| 23 os.rename(file, file + '~') | |
| 24 open(file, 'w').write(newdata) | |
| 25 print 'done.' | |
| 26 else: | |
| 27 print 'no change.' | |
| 28 | |
| 29 main() |
