From ac50510fa9361c7794d7439462861e7851fd9096 Mon Sep 17 00:00:00 2001 From: buliabyak Date: Sat, 14 Jun 2008 04:12:54 +0000 Subject: [PATCH] patch by sas from 227449 with my changes for using ps2pdf instead of pstoedit --- share/extensions/Makefile.am | 2 + share/extensions/eps_input.inx | 11 +++-- share/extensions/ps2pdf-ext.py | 30 ++++++++++++ share/extensions/ps_input.inx | 13 +++-- share/extensions/run_command.py | 86 +++++++++++++++++++++++++++++++++ share/extensions/uniconv-ext.py | 46 +----------------- 6 files changed, 135 insertions(+), 53 deletions(-) create mode 100644 share/extensions/ps2pdf-ext.py create mode 100644 share/extensions/run_command.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 73b5ad78a..909327cc9 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -80,6 +80,7 @@ extensions = \ ps2epsi.sh \ ps2pdf.cmd \ ps2pdf.sh \ + ps2pdf-ext.py \ pturtle.py \ radiusrand.py \ restack.py \ @@ -88,6 +89,7 @@ extensions = \ render_alphabetsoup_config.py \ rtree.py \ rubberstretch.py\ + run_command.py \ simplepath.py \ simplepath.rb \ simplestyle.py \ diff --git a/share/extensions/eps_input.inx b/share/extensions/eps_input.inx index 5529f003b..14f33764d 100644 --- a/share/extensions/eps_input.inx +++ b/share/extensions/eps_input.inx @@ -2,15 +2,18 @@ <_name>EPS Input org.inkscape.input.eps - pstoedit + org.inkscape.input.pdf + ps2pdf + ps2pdf-ext.py .eps image/x-encapsulated-postscript - <_filetypename>Encapsulated Postscript (*.eps) - <_filetypetooltip>Encapsulated Postscript + <_filetypename>Encapsulated PostScript (*.eps) + <_filetypetooltip>Encapsulated PostScript org.inkscape.output.eps diff --git a/share/extensions/ps2pdf-ext.py b/share/extensions/ps2pdf-ext.py new file mode 100644 index 000000000..80d98c040 --- /dev/null +++ b/share/extensions/ps2pdf-ext.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +""" +pstoedit-ext.py +Python script for running pstoedit in Inkscape extensions + +Copyright (C) 2008 Stephen Silver + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +""" + +import sys +from run_command import run + +#run('pstoedit -f plot-svg -dt -ssp "%s" "%%s"' % sys.argv[1], "pstoedit") + run('ps2pdf "%s" "%%s"' % sys.argv[1], "ps2pdf") + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 diff --git a/share/extensions/ps_input.inx b/share/extensions/ps_input.inx index 54b2b20f1..c7677ffe2 100644 --- a/share/extensions/ps_input.inx +++ b/share/extensions/ps_input.inx @@ -1,16 +1,19 @@ - <_name>Postscript Input + <_name>PostScript Input org.inkscape.input.ps - pstoedit + org.inkscape.input.pdf + ps2pdf + ps2pdf-ext.py .ps image/x-postscript - <_filetypename>Postscript (*.ps) - <_filetypetooltip>Postscript + <_filetypename>PostScript (*.ps) + <_filetypetooltip>PostScript org.inkscape.output.ps diff --git a/share/extensions/run_command.py b/share/extensions/run_command.py new file mode 100644 index 000000000..0919d767d --- /dev/null +++ b/share/extensions/run_command.py @@ -0,0 +1,86 @@ +import os +import sys +import tempfile + +""" +run_command.py +Module for running SVG-generating commands in Inkscape extensions + +Copyright (C) 2008 Stephen Silver + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +""" + +# Run a command that generates an SVG file from an input file. +# On success, outputs the contents of the SVG file to stdout, and exits +# with a return code of 0. +# On failure, outputs an error message to stderr, and exits with a return +# code of 1. +def run(command_format, prog_name): + svgfile = tempfile.mktemp(".svg") + command = command_format % svgfile + msg = None + # In order to get a return code from the process, we use subprocess.Popen + # if it's available (Python 2.4 onwards) and otherwise use popen2.Popen3 + # (Unix only). As the Inkscape package for Windows includes Python 2.5, + # this should cover all supported platforms. + try: + try: + from subprocess import Popen, PIPE + p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) + rc = p.wait() + out = p.stdout.read() + err = p.stderr.read() + except ImportError: + try: + from popen2 import Popen3 + p = Popen3(command, True) + p.wait() + rc = p.poll() + out = p.fromchild.read() + err = p.childerr.read() + except ImportError: + # shouldn't happen... + msg = "Neither subprocess.Popen nor popen2.Popen3 is available" + if rc and msg is None: + msg = "%s failed:\n%s\n%s\n" % (prog_name, out, err) + except Exception, inst: + msg = "Error attempting to run %s: %s" % (prog_name, str(inst)) + + # If successful, copy the SVG file to stdout. + if msg is None: + try: + f = open(svgfile, "rb") + data = f.read() + sys.stdout.write(data) + f.close() + except IOError, inst: + msg = "Error reading temporary SVG file: %s" % str(inst) + + # Clean up. + try: + os.remove(svgfile) + except Exception: + pass + + # Ouput error message (if any) and exit. + if msg is not None: + sys.stderr.write(msg + "\n") + sys.exit(1) + else: + sys.exit(0) + + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 diff --git a/share/extensions/uniconv-ext.py b/share/extensions/uniconv-ext.py index 63a76cad4..1197f97bb 100644 --- a/share/extensions/uniconv-ext.py +++ b/share/extensions/uniconv-ext.py @@ -19,54 +19,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - """ -import os -import random -import subprocess import sys -import tempfile - -# We need a filename ending in ".svg" for UniConvertor. -# This is a hack. -chars = list("0123456789abcdefghijklmnopqrstuvwxyz") -while True: - random.shuffle(chars) - svgfile = os.path.join(tempfile.gettempdir(), ''.join(chars) + '.svg') - if not os.path.exists(svgfile): - break - -# Run UniConvertor, and determine our return code. -try: - p = subprocess.Popen('uniconv "%s" "%s"' % (sys.argv[1], svgfile), - shell=True, stderr=subprocess.PIPE) - err = p.stderr.read() - rc = p.wait() - if rc: - sys.stderr.write("UniConvertor failed: %s\n" % err) - rc = 1 -except Exception, inst: - sys.stderr.write("Spawn error: %s\n" % str(inst)) - rc = 1 - -# If successful, copy the SVG file to stdout. -if rc == 0: - try: - f = open(svgfile, "rU") - for line in f: - sys.stdout.write(line) - f.close() - except IOError, inst: - sys.stderr.write("Error reading temporary SVG file: %s\n" % str(inst)) - rc = 1 +from run_command import run -# Clean up and return. -try: - os.remove(svgfile) -except Exception: - pass -sys.exit(rc) +run('uniconv "%s" "%%s"' % sys.argv[1], "UniConvertor") # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 -- 2.30.2