From c876f0c146e9279a48fc5b88dca3438a43772d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Forsman?= Date: Fri, 30 Dec 2022 13:09:12 +0100 Subject: [PATCH] nixos/test-driver: quote some shell command lines This makes them robust against paths with whitespace. --- nixos/lib/test-driver/test_driver/machine.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nixos/lib/test-driver/test_driver/machine.py b/nixos/lib/test-driver/test_driver/machine.py index cbf3aa733c44..9c154bdf13cd 100644 --- a/nixos/lib/test-driver/test_driver/machine.py +++ b/nixos/lib/test-driver/test_driver/machine.py @@ -101,14 +101,14 @@ def _perform_ocr_on_screenshot( tess_args = f"-c debug_file=/dev/null --psm 11" - cmd = f"convert {magick_args} {screenshot_path} tiff:{screenshot_path}.tiff" + cmd = f"convert {magick_args} '{screenshot_path}' 'tiff:{screenshot_path}.tiff'" ret = subprocess.run(cmd, shell=True, capture_output=True) if ret.returncode != 0: raise Exception(f"TIFF conversion failed with exit code {ret.returncode}") model_results = [] for model_id in model_ids: - cmd = f"tesseract {screenshot_path}.tiff - {tess_args} --oem {model_id}" + cmd = f"tesseract '{screenshot_path}.tiff' - {tess_args} --oem '{model_id}'" ret = subprocess.run(cmd, shell=True, capture_output=True) if ret.returncode != 0: raise Exception(f"OCR failed with exit code {ret.returncode}") @@ -744,7 +744,7 @@ class Machine: {"image": os.path.basename(filename)}, ): self.send_monitor_command(f"screendump {tmp}") - ret = subprocess.run(f"pnmtopng {tmp} > {filename}", shell=True) + ret = subprocess.run(f"pnmtopng '{tmp}' > '{filename}'", shell=True) os.unlink(tmp) if ret.returncode != 0: raise Exception("Cannot convert screenshot")