From cc63cb8a0c4aaf16b19d497796b54084c203b40e Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Mon, 4 Mar 2024 21:40:16 +0100 Subject: [PATCH] Use tmpfile for passing data to pstoedit Otherwise this fails on the web instance as itz is pretty old. This patch is not needed with newer versions of pstoedit and should be removed as soon as the web instance is on the new server. --- boxes/formats.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/boxes/formats.py b/boxes/formats.py index 6329d641..4b4ef19d 100644 --- a/boxes/formats.py +++ b/boxes/formats.py @@ -18,6 +18,7 @@ import shutil import subprocess import io +import tempfile from boxes.drawing import SVGSurface, PSSurface, LBRN2Surface, Context @@ -34,9 +35,9 @@ class Formats: "svg_Ponoko": None, "ps": None, "lbrn2": None, - "dxf": "{pstoedit} -flat 0.1 -f dxf:-mm", - "gcode": "{pstoedit} -f gcode", - "plt": "{pstoedit} -f hpgl", + "dxf": "{pstoedit} -flat 0.1 -f dxf:-mm {input} -", + "gcode": "{pstoedit} -f gcode {input} -", + "plt": "{pstoedit} -f hpgl {input} -", # "ai": "{pstoedit} -f ps2ai", "pdf": "{ps2pdf} -dEPSCrop - -", } @@ -82,11 +83,20 @@ def getSurface(self, fmt): def convert(self, data, fmt): if fmt not in self._BASE_FORMATS: + tmpfile = "" + if fmt in ("dxf", "gcode", "plt"): + fd, tmpfile = tempfile.mkstemp() + os.write(fd, data.getvalue()) + input_ = None + else: + input_ = data.getvalue() + cmd = self.formats[fmt].format( pstoedit=self.pstoedit, - ps2pdf=self.ps2pdf).split() + ps2pdf=self.ps2pdf, + input=tmpfile).split() - result = subprocess.run(cmd, input=data.getvalue(), capture_output=True) + result = subprocess.run(cmd, input=input_, capture_output=True) if result.returncode: # XXX show stderr output raise ValueError("Conversion failed. pstoedit returned %i\n\n %s" % (result.returncode, result.stderr))