MCPcopy Create free account
hub / github.com/numpy/numpy / dos2unix

Function dos2unix

numpy/distutils/line_endings.py:9–28  ·  view source on GitHub ↗

Replace CRLF with LF in argument files. Print names of changed files.

(file)

Source from the content-addressed store, hash-verified

7
8
9def 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
30def dos2unix_one_dir(modified_files, dir_name, file_names):
31 for file in file_names:

Callers 1

dos2unix_one_dirFunction · 0.85

Calls 4

printFunction · 0.85
openFunction · 0.85
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected