Replace LF with CRLF in argument files. Print names of changed files.
(file)
| 41 | #---------------------------------- |
| 42 | |
| 43 | def unix2dos(file): |
| 44 | "Replace LF with CRLF in argument files. Print names of changed files." |
| 45 | if os.path.isdir(file): |
| 46 | print(file, "Directory!") |
| 47 | return |
| 48 | |
| 49 | with open(file, "rb") as fp: |
| 50 | data = fp.read() |
| 51 | if '\0' in data: |
| 52 | print(file, "Binary!") |
| 53 | return |
| 54 | newdata = re.sub("\r\n", "\n", data) |
| 55 | newdata = re.sub("\n", "\r\n", newdata) |
| 56 | if newdata != data: |
| 57 | print('unix2dos:', file) |
| 58 | with open(file, "wb") as f: |
| 59 | f.write(newdata) |
| 60 | return file |
| 61 | else: |
| 62 | print(file, 'ok') |
| 63 | |
| 64 | def unix2dos_one_dir(modified_files, dir_name, file_names): |
| 65 | for file in file_names: |
no test coverage detected