Replace CRLF with LF in argument files. Print names of changed files.
(file)
| 7 | |
| 8 | |
| 9 | def dos2unix(file): |
| 10 | "Replace CRLF with LF in argument files. Print names of changed files." |
| 11 | if os.path.isdir(file): |
| 12 | print(file, "Directory!") |
| 13 | return |
| 14 | |
| 15 | with open(file, "rb") as fp: |
| 16 | data = fp.read() |
| 17 | if '\0' in data: |
| 18 | print(file, "Binary!") |
| 19 | return |
| 20 | |
| 21 | newdata = re.sub("\r\n", "\n", data) |
| 22 | if newdata != data: |
| 23 | print('dos2unix:', file) |
| 24 | with open(file, "wb") as f: |
| 25 | f.write(newdata) |
| 26 | return file |
| 27 | else: |
| 28 | print(file, 'ok') |
| 29 | |
| 30 | def dos2unix_one_dir(modified_files, dir_name, file_names): |
| 31 | for file in file_names: |
no test coverage detected