-def fix_newlines(file, log=True):
- """
- Normalizes newlines in a file into UNIX file endings. If
- ``log`` is ``True`` an info log mesage is printed if
- any normalization occurs. Return value is ``True`` if
- normalization occurred.
- """
- old_contents = open(file, "r").read()
- contents = old_contents
- while "\r\n" in contents:
- contents = contents.replace("\r\n", "\n")
- contents = contents.replace("\r", "\n")
- if contents != old_contents:
- logging.info("Converted %s to UNIX file endings" % file)
- open(file, "w").write(contents)
- return True
- return False