scripts: zephyr_flash_debug: improve debug logging
Ensure that the printed commands can be copy/pasted into a shell with
the same semantics.
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
diff --git a/scripts/support/zephyr_flash_debug.py b/scripts/support/zephyr_flash_debug.py
index a05c95a..69b1b72 100755
--- a/scripts/support/zephyr_flash_debug.py
+++ b/scripts/support/zephyr_flash_debug.py
@@ -48,15 +48,22 @@
return default_value
+def quote_sh_list(cmd):
+ '''Transform a command from list into shell string form.'''
+ fmt = ' '.join('{}' for _ in cmd)
+ args = [shlex.quote(s) for s in cmd]
+ return fmt.format(*args)
+
+
def check_call(cmd, debug):
if debug:
- print(' '.join(cmd))
+ print(quote_sh_list(cmd))
subprocess.check_call(cmd)
def check_output(cmd, debug):
if debug:
- print(' '.join(cmd))
+ print(quote_sh_list(cmd))
return subprocess.check_output(cmd)
@@ -74,7 +81,7 @@
preexec = os.setsid
if debug:
- print(' '.join(cmd))
+ print(quote_sh_list(cmd))
return subprocess.Popen(cmd, creationflags=cflags, preexec_fn=preexec)