better error handling

This commit is contained in:
Mario Voigt 2022-12-03 22:51:35 +01:00
parent 10f4794199
commit 6afcf1efc5

View File

@ -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))