scripts: runner: add internal DEBUG to core
Add a debug-only global that prevents commands from running, and just
prints what would have been run.
Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
diff --git a/scripts/support/runner/core.py b/scripts/support/runner/core.py
index 8c32cdd..2004400 100644
--- a/scripts/support/runner/core.py
+++ b/scripts/support/runner/core.py
@@ -20,6 +20,21 @@
import subprocess
+# Turn on to enable just printing the commands that would be run,
+# without actually running them. This can break runners that are expecting
+# output or if one command depends on another, so it's just for debugging.
+DEBUG = False
+
+
+class _DebugDummyPopen:
+
+ def terminate(self):
+ pass
+
+ def wait(self):
+ pass
+
+
def quote_sh_list(cmd):
'''Transform a command from list into shell string form.'''
fmt = ' '.join('{}' for _ in cmd)
@@ -410,8 +425,12 @@
subprocess and check that it executed correctly, rather than
using subprocess directly, to keep accurate debug logs.
'''
- if self.debug:
+ if DEBUG or self.debug:
print(quote_sh_list(cmd))
+
+ if DEBUG:
+ return
+
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
@@ -427,6 +446,10 @@
'''
if self.debug:
print(quote_sh_list(cmd))
+
+ if DEBUG:
+ return b''
+
try:
return subprocess.check_output(cmd)
except subprocess.CalledProcessError:
@@ -446,7 +469,10 @@
elif system in {'Linux', 'Darwin'}:
preexec = os.setsid
- if self.debug:
+ if DEBUG or self.debug:
print(quote_sh_list(cmd))
+ if DEBUG:
+ return _DebugDummyPopen()
+
return subprocess.Popen(cmd, creationflags=cflags, preexec_fn=preexec)