1 | n/a | #! /usr/bin/env python3 |
---|
2 | n/a | |
---|
3 | n/a | "Replace LF with CRLF in argument files. Print names of changed files." |
---|
4 | n/a | |
---|
5 | n/a | import sys, re, os |
---|
6 | n/a | |
---|
7 | n/a | def main(): |
---|
8 | n/a | for filename in sys.argv[1:]: |
---|
9 | n/a | if os.path.isdir(filename): |
---|
10 | n/a | print(filename, "Directory!") |
---|
11 | n/a | continue |
---|
12 | n/a | with open(filename, "rb") as f: |
---|
13 | n/a | data = f.read() |
---|
14 | n/a | if b'\0' in data: |
---|
15 | n/a | print(filename, "Binary!") |
---|
16 | n/a | continue |
---|
17 | n/a | newdata = re.sub(b"\r?\n", b"\r\n", data) |
---|
18 | n/a | if newdata != data: |
---|
19 | n/a | print(filename) |
---|
20 | n/a | with open(filename, "wb") as f: |
---|
21 | n/a | f.write(newdata) |
---|
22 | n/a | |
---|
23 | n/a | if __name__ == '__main__': |
---|
24 | n/a | main() |
---|