Python

Simple Dos2unix python Application.

Note I found that using the same code to make a package between both windows and linux based system often had issues with file directories. This maybe because we only used internally created libraries,this is common in some area. The original libraries perhaps didnt consider cross platform compatibility. Its not something I came across in general. One remaining issue is I still prefer to use Bash to wrap some scripts, which means git-bash on windows, however this does not present itself well in system like uname. I often add switches to handle the different platforms and sub platforms.

import sys
filename = sys.argv[2]
operation = sys.argv[1]


if operation == 'dos2unix':
    text = open(filename, 'rb').read().replace(b'\r\n', b'\n')
    print(text)
    open(filename, 'wb').write(text)
elif operation == 'unix2dos':
    text = open(filename, 'r').read().replace('\n', '\r\n')
    open(filename, 'w').write(text)
else:
    sys.exit('Possible args can be dos2unix or unix2dos')