cmd/crlf.py

29 lines
664 B
Python
Raw Normal View History

2019-06-12 05:41:31 +00:00
'''
Convert LF line endings to CRLF.
'''
import sys
from voussoirkit import pipeable
from voussoirkit import winglob
2019-06-12 05:41:31 +00:00
CR = b'\x0D'
LF = b'\x0A'
CRLF = CR + LF
def crlf(filename):
with open(filename, 'rb') as handle:
content = handle.read()
content = content.replace(CRLF, LF)
content = content.replace(LF, CRLF)
with open(filename, 'wb') as handle:
handle.write(content)
def main(args):
for line in pipeable.go(args, strip=True, skip_blank=True):
for filename in winglob.glob(line):
2019-06-12 05:41:31 +00:00
pipeable.output(filename)
crlf(filename)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))