]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/prefs2prefs.py
Merge branch 'master' of git.lyx.org:lyx
[lyx.git] / lib / scripts / prefs2prefs.py
index 5bc25c1b142289fe89f4c334268ddbfe290242dc..3026d061637e0acb4f45fa9b804e59f452d5568b 100644 (file)
@@ -48,7 +48,7 @@ def trim_bom(line):
 
 def read(source):
        " Read input file and strip lineendings."
-       lines = source.read().splitlines()
+       lines = source.read().splitlines() or ['']
        lines[0] = trim_bom(lines[0])
        return lines
 
@@ -120,7 +120,7 @@ def usage():
        print "or: %s [-l] [-p] <infile >outfile" % sys.argv[0]
        print "  -l: convert LFUNs (bind and ui files)"
        print "  -p: convert preferences"
-       print "Note that one of -l and -p is required."
+       print "Note that exactly one of -l and -p is required."
 
 
 def main(argv):
@@ -155,7 +155,11 @@ def main(argv):
        
        if not conversions:
                usage()
-               print "\nNeither -l nor -p given"
+               print "\nNeither -l nor -p given."
+               sys.exit(1)
+       elif len(options) > 1:
+               usage()
+               print "\nOnly one of -l or -p should be given."
                sys.exit(1)
 
        current_format = len(conversions)
@@ -163,17 +167,24 @@ def main(argv):
        format = get_format(lines)
 
        while format < current_format:
-               for c in conversions[format]:
+               target_format, convert = conversions[format]
+               old_format = format
+
+               # make sure the conversion list is sequential
+               if int(old_format) + 1 != target_format:
+                       sys.stderr.write("Something is wrong with the conversion chain.\n")
+                       sys.exit(1)
+
+               for c in convert:
                        for i in range(len(lines)):
                                (update, newline) = c(lines[i])
                                if update:
                                        lines[i] = newline
 
                update_format(lines)
+               format = get_format(lines)
 
                # sanity check
-               old_format = format
-               format = get_format(lines)
                if int(old_format) + 1 != int(format):
                        sys.stderr.write("Failed to convert to new format!\n")
                        sys.exit(1)