]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/resolve.py
Hookify research interface.
[wizard.git] / wizard / resolve.py
index 9111203ec5d60c06fce10e2f97a29396a4dcc290..9259c245330c5d90140527f867d2ab65fa37cc17 100644 (file)
@@ -59,6 +59,7 @@ then the user matched globs.
 
 import re
 import itertools
+import logging
 
 re_var = re.compile("^\*\*\*(\d+)\*\*\*\\\n", re.MULTILINE)
 
@@ -122,3 +123,21 @@ def resolve(contents, spec, result):
 def is_conflict(contents):
     # Really really simple heuristic
     return "<<<<<<<" in contents
+
+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