]> git.lyx.org Git - lyx.git/blob - lib/scripts/fig2pstex.py
Fix encoding of filenames in python scripts
[lyx.git] / lib / scripts / fig2pstex.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # file fig2pstex.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7 #
8 # \author Angus Leeming
9 # \author Bo Peng
10 #
11 # Full author contact details are available in file CREDITS
12
13
14 # This script converts an XFIG image to something that latex can process
15 # into high quality PostScript.
16
17 # Usage:
18 #   python fig2pstex.py ${base}.fig ${base}.pstex
19 # This command generates
20 #   ${base}.eps    the converted eps file
21 #   ${base}.pstex  a tex file that can be included in your latex document
22 #       using '\input{${output}}'.
23 #
24 # Note:
25 #   Do not use this command as
26 #     python fig2pstex.py file.fig file.eps
27 #   the real eps file will be overwritten by a tex file named file.eps.
28 #
29
30 import os, sys, locale
31
32 # We expect two args, the names of the input and output files.
33 if len(sys.argv) != 3:
34     sys.exit(1)
35
36 language, output_encoding = locale.getdefaultlocale()
37 if output_encoding == None:
38     output_encoding = 'latin1'
39
40 input = unicode(sys.argv[1], 'utf8').encode(output_encoding)
41 output = unicode(sys.argv[2], 'utf8').encode(output_encoding)
42
43 # Fail silently if the file doesn't exist
44 if not os.path.isfile(input):
45     sys.exit(0)
46
47 # Strip the extension from ${output}
48 outbase = os.path.splitext(output)[0]
49
50 # Generate the EPS file
51 # Generate the PSTEX_T file
52 if os.system('fig2dev -Lpstex %s %s.eps' % (input, outbase)) != 0 or \
53   os.system('fig2dev -Lpstex_t -p%s %s %s' % (outbase, input, output)) != 0:
54   print 'fig2dev fails'
55   sys.exit(1)