Solver: Fix command line parsing (again).

results
Pierre-Antoine Rouby 2023-08-07 16:20:38 +02:00
parent dcc6e2df2d
commit 798d9198d6
1 changed files with 11 additions and 8 deletions

View File

@ -176,17 +176,20 @@ class AbstractSolver(object):
)
)
def _format_command(self, cmd):
def _format_command(self, cmd, path = ""):
"""Format command line
Args:
cmd: The command line
path: Optional path string (replace @path in cmd)
Returns:
The executable and list of arguments
"""
# HACK: Works in most case... Trust me i'm an engineer
cmd = cmd.replace("@install_dir", self._install_dir())
cmd = cmd.replace("@path", self._path_input)
cmd = cmd.replace("@path", path.replace(" ", "\ "))
cmd = cmd.replace("@input", self.input_param())
cmd = cmd.replace("@dir", self._process.workingDirectory())
@ -195,13 +198,13 @@ class AbstractSolver(object):
if cmd[0] == "\"":
# Command line executable path is between " char
cmd = cmd.split("\"")
exe = cmd[1]
exe = cmd[1].replace("\ ", " ")
args = "\"".join(cmd[2:]).split(" ")[1:]
else:
# We suppose the command line executable path as no space char
cmd = cmd.replace("\ ", "&_&").split(" ")
exe = cmd[0].replace("&_&", "\ ")
args = cmd[1:]
exe = cmd[0].replace("&_&", " ")
args = list(map(lambda s: s.replace("&_&", "\ "), cmd[1:]))
logger.info(f"! {exe} {args}")
return exe, args
@ -212,7 +215,7 @@ class AbstractSolver(object):
return True
cmd = self._cmd_input
exe, args = self._format_command(cmd)
exe, args = self._format_command(cmd, self._path_input)
if not os.path.exists(exe):
error = f"[ERROR] Path {exe} do not exists"
@ -231,7 +234,7 @@ class AbstractSolver(object):
return True
cmd = self._cmd_solver
exe, args = self._format_command(cmd)
exe, args = self._format_command(cmd, self._path_solver)
if not os.path.exists(exe):
error = f"[ERROR] Path {exe} do not exists"
@ -251,7 +254,7 @@ class AbstractSolver(object):
return True
cmd = self._cmd_output
exe, args = self._format_command(cmd)
exe, args = self._format_command(cmd, self._path_output)
if not os.path.exists(exe):
error = f"[ERROR] Path {exe} do not exists"