From 6afcf1efc57315dd50feee6c44a3bee547248c21 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sat, 3 Dec 2022 22:51:35 +0100 Subject: [PATCH] better error handling --- .../svg_embed_and_crop/svg_embed_and_crop.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/extensions/fablabchemnitz/svg_embed_and_crop/svg_embed_and_crop.py b/extensions/fablabchemnitz/svg_embed_and_crop/svg_embed_and_crop.py index 133fe84..a007014 100644 --- a/extensions/fablabchemnitz/svg_embed_and_crop/svg_embed_and_crop.py +++ b/extensions/fablabchemnitz/svg_embed_and_crop/svg_embed_and_crop.py @@ -11,15 +11,23 @@ class EmbedAndCrop(inkex.EffectExtension): ''' def effect(self): + cp = os.path.dirname(os.path.abspath(__file__)) + "/svg_embed_and_crop/*" output_file = self.options.input_file + ".cropped" - cli_output = command.call('java', '-cp', cp, 'edu.emory.cellbio.svg.EmbedAndCropInkscapeEntry', self.options.input_file, "-o", output_file) - if len(cli_output) > 0: - self.debug(_("Inkscape extension returned the following output:")) - self.debug(cli_output) + + cmd = 'java -cp "' + cp + '" "edu.emory.cellbio.svg.EmbedAndCropInkscapeEntry" "' + self.options.input_file + '" -o "' + output_file + '"' + with subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: + proc.wait() + stdout, stderr = proc.communicate() + if stderr.decode('utf-8') != "": + inkex.utils.debug(stderr.decode('utf-8')) + #cli_output = command.call('java', '-cp', cp, 'edu.emory.cellbio.svg.EmbedAndCropInkscapeEntry', self.options.input_file, "-o", output_file) + #if len(cli_output) > 0: + # self.debug(_("Inkscape extension returned the following output:")) + # self.debug(cli_output) if not os.path.exists(output_file): - raise inkex.AbortExtension("Plugin canceled") + raise inkex.AbortExtension("Plugin cancelled") stream = open(output_file, 'r') p = etree.XMLParser(huge_tree=True) doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True))