boxes_proxy (for Inkscape): Quote command line options

and clean code up a bit
This commit is contained in:
Florian Festi 2023-02-08 23:08:52 +01:00
parent 8b961797f9
commit d511268c74
1 changed files with 10 additions and 10 deletions

View File

@ -17,6 +17,7 @@ import sys
import os import os
from lxml import etree from lxml import etree
import tempfile import tempfile
from shlex import quote
class boxesPyWrapper(inkex.GenerateExtension): 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 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): for arg in vars(self.options):
if arg != "output" and arg != "ids" and arg != "selected_nodes": if arg in (
#inkex.utils.debug(str(arg) + " = " + str(getattr(self.options, arg))) "output", "ids", "selected_nodes", "input_file", "tab"):
#fix behaviour of "original" arg which does not correctly gets interpreted if set to false continue
if arg == "original" and str(getattr(self.options, arg)) == "false": #fix behaviour of "original" arg which does not correctly gets
continue # interpreted if set to false
if arg in ("input_file", "tab"): if arg == "original" and str(getattr(self.options, arg)) == "false":
continue continue
else: cmd += f" --{arg} {quote(str(getattr(self.options, arg)))}"
cmd += " --" + arg + " " + 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 += " --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") cmd = cmd.replace("boxes --generator", "boxes")
# run boxes with the parameters provided # run boxes with the parameters provided