[Spambayes] \r\n endings
Guido van Rossum
guido@python.org
Thu, 26 Sep 2002 15:15:05 -0400
> Guilty, sorry.
>
> I'm using Pythonwin via Samba, but checking in using cvs on
> linux. Hence, I never saw the \r's, and cvs diff didn't show me
> adding \r's when I modified TestDriver.py
>
> Anyone know the best way to keep this from happening in the future?
> Pythonwin doesn't seem to have an option to control line endings.
You could write a script that you run on Linux before you check in.
Here's what I use; I call it "crlf":
#! /usr/bin/env python
import sys, re, os
for file in sys.argv[1:]:
if os.path.isdir(file):
print file, "Directory!"
continue
data = open(file, "rb").read()
if '\0' in data:
print file, "Binary!"
continue
newdata = re.sub(r"\r\n", r"\n", data)
if newdata != data:
print file
f = open(file, "wb")
f.write(newdata)
f.close()
--Guido van Rossum (home page: http://www.python.org/~guido/)