From d511268c74a27c1befbf493a5f4a9f3b0820fb39 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Wed, 8 Feb 2023 23:08:52 +0100 Subject: [PATCH] boxes_proxy (for Inkscape): Quote command line options and clean code up a bit --- scripts/boxes_proxy.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/boxes_proxy.py b/scripts/boxes_proxy.py index cb88624..2d61bcd 100644 --- a/scripts/boxes_proxy.py +++ b/scripts/boxes_proxy.py @@ -17,6 +17,7 @@ import sys import os from lxml import etree import tempfile +from shlex import quote class boxesPyWrapper(inkex.GenerateExtension): @@ -36,16 +37,15 @@ class boxesPyWrapper(inkex.GenerateExtension): cmd = "boxes" #boxes.exe in this local dir (or if present in %PATH%), or boxes from $PATH in linux for arg in vars(self.options): - if arg != "output" and arg != "ids" and arg != "selected_nodes": - #inkex.utils.debug(str(arg) + " = " + str(getattr(self.options, arg))) - #fix behaviour of "original" arg which does not correctly gets interpreted if set to false - if arg == "original" and str(getattr(self.options, arg)) == "false": - continue - if arg in ("input_file", "tab"): - continue - else: - cmd += " --" + arg + " " + str(getattr(self.options, arg)) - cmd += " --output " + box_file + " " + box_file #we need to add box_file string twice in a row. Otherwise program executable throws an error + if arg in ( + "output", "ids", "selected_nodes", "input_file", "tab"): + continue + #fix behaviour of "original" arg which does not correctly gets + # interpreted if set to false + if arg == "original" and str(getattr(self.options, arg)) == "false": + continue + cmd += f" --{arg} {quote(str(getattr(self.options, arg)))}" + cmd += f" --output {box_file} {box_file}" #we need to add box_file string twice in a row. Otherwise program executable throws an error cmd = cmd.replace("boxes --generator", "boxes") # run boxes with the parameters provided