ยปCore Development>Code coverage>Tools/scripts/crlf.py

Python code coverage for Tools/scripts/crlf.py

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