2 # -*- coding: utf-8 -*-
4 # file libreoffice2eps.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
8 # \author Tommaso Cucinotta
10 # Full author contact details are available in file CREDITS
13 # This script converts an OpenOffice drawing to EPS.
16 # python libreoffice2eps.py input.odg output.eps
18 import os, sys, tempfile, shutil
22 run a command, quit if fails
24 if os.system(cmd) != 0:
25 print "Command '%s' failed." % cmd
28 # We expect two args, the names of the input and output files.
29 if len(sys.argv) != 3:
32 input, output = sys.argv[1:]
34 # Fail silently if the file doesn't exist
35 if not os.path.isfile(input):
38 tmpdir = tempfile.mkdtemp()
39 fname = os.path.splitext(os.path.basename(input))[0]
41 # Generate the EPS file
42 runCommand('libreoffice -nologo -headless -convert-to eps -outdir "%s" "%s"' % (tmpdir, input))
43 shutil.move('%s/%s.eps' % (tmpdir, fname), '%s/%s.ps' % (tmpdir, fname))
44 runCommand('ps2eps "%s/%s.ps"' % (tmpdir, fname))
45 shutil.move('%s/%s.eps' % (tmpdir, fname), output)
46 os.remove('%s/%s.ps' % (tmpdir, fname))