1
0
mirror of https://git.lyx.org/repos/lyx.git synced 2025-01-03 16:31:13 +00:00

care to make prefs2prefs.py python 3 compatible

This commit is contained in:
Stephan Witt 2017-04-08 20:58:16 +02:00
parent ebbc638de8
commit 4a009c85bb

View File

@ -31,15 +31,17 @@
# These will be different for the bind and ui files and for the preferences # These will be different for the bind and ui files and for the preferences
# file. # file.
from __future__ import print_function
import os, re, string, sys import os, re, string, sys
from getopt import getopt from getopt import getopt
import io
########################################################### ###########################################################
# Utility functions, borrowed from layout2layout.py # Utility functions, borrowed from layout2layout.py
def trim_bom(line): def trim_bom(line):
" Remove byte order mark." " Remove byte order mark."
if line[0:3] == "\357\273\277": if line[0:3] == u"\357\273\277":
return line[3:] return line[3:]
else: else:
return line return line
@ -119,11 +121,11 @@ def abort(msg):
########################################################### ###########################################################
def usage(): def usage():
print "%s [-l] [-p] infile outfile" % sys.argv[0] print ("%s [-l] [-p] infile outfile" % sys.argv[0])
print "or: %s [-l] [-p] <infile >outfile" % sys.argv[0] print ("or: %s [-l] [-p] <infile >outfile" % sys.argv[0])
print " -l: convert LFUNs (bind and ui files)" print (" -l: convert LFUNs (bind and ui files)")
print " -p: convert preferences" print (" -p: convert preferences")
print "Note that exactly one of -l and -p is required." print ("Note that exactly one of -l and -p is required.")
def main(argv): def main(argv):
@ -139,8 +141,8 @@ def main(argv):
source = sys.stdin source = sys.stdin
output = sys.stdout output = sys.stdout
elif len(args) == 2: elif len(args) == 2:
source = open(args[0], 'rb') source = io.open(args[0], 'r', encoding='utf_8', errors='surrogateescape')
output = open(args[1], 'wb') output = io.open(args[1], 'w', encoding='utf_8', newline='\n')
opened_files = True opened_files = True
else: else:
usage() usage()