From 71ebf846bb92187f16f23fe3429028d6e2a3e689 Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Mon, 19 Sep 2011 00:37:15 +0000 Subject: [PATCH] Adding the script missing from last commit. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39707 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/scripts/libreoffice2eps.py | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 lib/scripts/libreoffice2eps.py diff --git a/lib/scripts/libreoffice2eps.py b/lib/scripts/libreoffice2eps.py new file mode 100755 index 0000000000..c7329c261e --- /dev/null +++ b/lib/scripts/libreoffice2eps.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# file libreoffice2eps.py +# This file is part of LyX, the document processor. +# Licence details can be found in the file COPYING. +# +# \author Tommaso Cucinotta +# +# Full author contact details are available in file CREDITS + + +# This script converts an OpenOffice drawing to EPS. + +# Usage: +# python libreoffice2eps.py input.odg output.eps + +import os, sys, tempfile, shutil + +def runCommand(cmd): + ''' Utility function: + run a command, quit if fails + ''' + if os.system(cmd) != 0: + print "Command '%s' failed." % cmd + sys.exit(1) + +# We expect two args, the names of the input and output files. +if len(sys.argv) != 3: + sys.exit(1) + +input, output = sys.argv[1:] + +# Fail silently if the file doesn't exist +if not os.path.isfile(input): + sys.exit(0) + +tmpdir = tempfile.mkdtemp() +fname = os.path.splitext(os.path.basename(input))[0] + +# Generate the EPS file +runCommand('libreoffice -nologo -headless -convert-to eps -outdir "%s" "%s"' % (tmpdir, input)) +shutil.move('%s/%s.eps' % (tmpdir, fname), '%s/%s.ps' % (tmpdir, fname)) +runCommand('ps2eps "%s/%s.ps"' % (tmpdir, fname)) +shutil.move('%s/%s.eps' % (tmpdir, fname), output) +os.remove('%s/%s.ps' % (tmpdir, fname)) +os.rmdir(tmpdir) -- 2.39.2