""" Functions for converting from DOS to UNIX line endings """ import os import re import sys def dos2unix(file): "Replace CRLF with LF in argument files. Print names of changed files." if os.path.isdir(file): print(file, "Directory!") return with open(file, "rb") as fp: data = fp.read() if '\0' in data: print(file, "Binary!") return newdata = re.sub("\r\n", "\n", data) if newdata != data: print('dos2unix:', file) with open(file, "wb") as f: f.write(newdata) return file else: print(file, 'ok') def dos2unix_one_dir(modified_files, dir_name, file_names): for file in file_names: full_path = os.path.join(dir_name, file) file = dos2unix(full_path) if file is not None: modified_files.append(file) def dos2unix_dir(dir_name): modified_files = [] os.path.walk(dir_name, dos2unix_one_dir, modified_files) return modified_files #---------------------------------- def unix2dos(file): "Replace LF with CRLF in argument files. Print names of changed files." if os.path.isdir(file): print(file, "Directory!") return with open(file, "rb") as fp: data = fp.read() if '\0' in data: print(file, "Binary!") return newdata = re.sub("\r\n", "\n", data) newdata = re.sub("\n", "\r\n", newdata) if newdata != data: print('unix2dos:', file) with open(file, "wb") as f: f.write(newdata) return file else: print(file, 'ok') def unix2dos_one_dir(modified_files, dir_name, file_names): for file in file_names: full_path = os.path.join(dir_name, file) unix2dos(full_path) if file is not None: modified_files.append(file) def unix2dos_dir(dir_name): modified_files = [] os.path.walk(dir_name, unix2dos_one_dir, modified_files) return modified_files if __name__ == "__main__": dos2unix_dir(sys.argv[1])
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 0755 |
|
|
checks | Folder | 0755 |
|
|
command | Folder | 0755 |
|
|
fcompiler | Folder | 0755 |
|
|
mingw | Folder | 0755 |
|
|
tests | Folder | 0755 |
|
|
__config__.py | File | 5.02 KB | 0644 |
|
__init__.py | File | 2.03 KB | 0644 |
|
__init__.pyi | File | 119 B | 0644 |
|
_shell_utils.py | File | 2.55 KB | 0644 |
|
armccompiler.py | File | 962 B | 0644 |
|
ccompiler.py | File | 27.95 KB | 0644 |
|
ccompiler_opt.py | File | 97.98 KB | 0644 |
|
conv_template.py | File | 9.31 KB | 0644 |
|
core.py | File | 7.98 KB | 0644 |
|
cpuinfo.py | File | 22.11 KB | 0644 |
|
exec_command.py | File | 10.04 KB | 0644 |
|
extension.py | File | 3.48 KB | 0644 |
|
from_template.py | File | 7.73 KB | 0644 |
|
fujitsuccompiler.py | File | 834 B | 0644 |
|
intelccompiler.py | File | 4.13 KB | 0644 |
|
lib2def.py | File | 3.54 KB | 0644 |
|
line_endings.py | File | 1.98 KB | 0644 |
|
log.py | File | 2.81 KB | 0644 |
|
mingw32ccompiler.py | File | 21.55 KB | 0644 |
|
misc_util.py | File | 87.26 KB | 0644 |
|
msvc9compiler.py | File | 2.14 KB | 0644 |
|
msvccompiler.py | File | 2.58 KB | 0644 |
|
npy_pkg_config.py | File | 12.67 KB | 0644 |
|
numpy_distribution.py | File | 634 B | 0644 |
|
pathccompiler.py | File | 713 B | 0644 |
|
setup.py | File | 634 B | 0644 |
|
system_info.py | File | 110.53 KB | 0644 |
|
unixccompiler.py | File | 5.3 KB | 0644 |
|