X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=lib%2Fscripts%2Ffig_copy.py;h=a398c1dbf526b249b34098dddec5f40aa0e58fbd;hb=48a5b16885255faecf70bdab771644be13fd7261;hp=ac2948b5f7f3e542d1503f229bf9e167e3784f29;hpb=cff50172f32f3f9203155790c67601225ea1e354;p=lyx.git diff --git a/lib/scripts/fig_copy.py b/lib/scripts/fig_copy.py index ac2948b5f7..a398c1dbf5 100644 --- a/lib/scripts/fig_copy.py +++ b/lib/scripts/fig_copy.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- # file fig_copy.py @@ -18,31 +17,25 @@ # picture files that are stored as relative paths are replaced # with the absolute path. -import os, sys, locale +from __future__ import print_function +import os, sys if len(sys.argv) != 3: - print >> sys.stderr, "Usage: fig_copy.py " + print ("Usage: fig_copy.py ", file=sys.stderr) sys.exit(1) -language, output_encoding = locale.getdefaultlocale() -if output_encoding == None: - output_encoding = 'latin1' - -from_file = unicode(sys.argv[1], 'utf8').encode(output_encoding) -to_file = unicode(sys.argv[2], 'utf8').encode(output_encoding) - -if not os.path.isfile(from_file): - print >> sys.stderr, "Unable to read", from_file +if not os.path.isfile(sys.argv[1]): + print ("Unable to read", sys.argv[1], file=sys.stderr) sys.exit(1) -from_dir = os.path.split(os.path.realpath(from_file))[0] -to_dir = os.path.split(os.path.realpath(to_file))[0] +from_dir = os.path.split(os.path.realpath(sys.argv[1]))[0] +to_dir = os.path.split(os.path.realpath(sys.argv[2]))[0] # The work is trivial if "to" and "from" are in the same directory. if from_dir == to_dir: import shutil try: - shutil.copy(from_file, to_file) + shutil.copy(sys.argv[1], sys.argv[2]) except: sys.exit(1) sys.exit(0) @@ -53,20 +46,20 @@ import re # We're looking for a line of text that defines an entry of # type '2' (a polyline), subtype '5' (an external picture file). # The line has 14 other data fields. -patternline = re.compile(r'^\s*2\s+5(\s+[0-9.+-]+){14}\s*$') -emptyline = re.compile(r'^\s*$') -commentline = re.compile(r'^\s*#.*$') +patternline = re.compile(br'^\s*2\s+5(\s+[0-9.+-]+){14}\s*$') +emptyline = re.compile(br'^\s*$') +commentline = re.compile(br'^\s*#.*$') # we allow space in path name -figureline = re.compile(r'^(\s*[01]\s*)(\S[\S ]*)(\s*)$') +figureline = re.compile(br'^(\s*[01]\s*)(\S[\S ]*)(\s*)$') -input = open(from_file, 'r') -output = open(to_file, 'w') +input = open(sys.argv[1], 'rb') +output = open(sys.argv[2], 'wb') # path in the fig is relative to this path os.chdir(from_dir) found = False -for line in input.xreadlines(): +for line in input: if found and not emptyline.match(line) and not commentline.match(line): # The contents of the final line containing the file name # are ' X ', where X = 0 or 1. @@ -76,7 +69,7 @@ for line in input.xreadlines(): found = False elif patternline.match(line): found = True - print >> output, line, + output.write(line) input.close() output.close()