Solver: Refactoring command line parser and add unittest.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-10-27 11:05:16 +02:00
1 parent 51c912f3a8
commit 6c794d2eb4
5 files changed
+232 -23

No files matched your search

+5 -23
View File
@@ -19,7 +19,7 @@
import os
import logging
from tools import timer
from tools import timer, parse_command_line
try:
# Installation allow Unix-like signal
@@ -146,9 +146,8 @@ class CommandLineSolver(AbstractSolver):
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", path.replace(" ", "%20"))
cmd = cmd.replace("\"@path\"", path)
cmd = cmd.replace("@input", self.input_param())
cmd = cmd.replace("@output", self.output_param())
cmd = cmd.replace("@dir", self._process.workingDirectory())
@@ -156,26 +155,9 @@ class CommandLineSolver(AbstractSolver):
logger.debug(f"! {cmd}")
if cmd[0] == "\"":
# Command line executable path is between " char
cmd = cmd.split("\"")
exe = cmd[1].replace("%20", " ")
args = list(
filter(
lambda s: s != "",
"\"".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 = list(
filter(
lambda s: s != "",
map(lambda s: s.replace("&_&", " "), cmd[1:])
)
)
words = parse_command_line(cmd)
exe = words[0]
args = words[1:]
logger.info(f"! {exe} {args}")
return exe, args