#! /usr/bin/env python import sys, os def main(): """u2m.py [infiles]\n\nConvert UNIX-style line breaks ('\\n') to mac style ('\\r').""" # note the excessive error-checking! args = sys.argv[1:] if len(args) == 0 or args[0].lower() in 'h -h help -help'.split(): print main.__doc__ sys.exit(0) for arg in args: try: instr = open(arg).read() except IOError: print "Error reading file %s" % arg continue filename = os.path.split(arg)[1] tempname = '/tmp/' + filename try: outfile = open(tempname,'w') outfile.write(instr.replace('\n','\r')) except IOError: print "Error creating file %s" % tempname continue try: os.rename(tempname, arg) except IOError: print "Error moving %s to %s" % (tempname, arg) continue print 'Converted %s to mac format' % arg main()