xtensa-build-zephyr.py: un-hardcode execute_command() wrapper

Duplicating all parameters of subprocess.run() is not just tedious and
error-prone, it makes the script compatible only with a range of
specific Python versions.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This commit is contained in:
Marc Herbert 2022-03-10 18:15:28 +00:00 committed by Liam Girdwood
parent f039b9eda1
commit d8572420d0
1 changed files with 6 additions and 9 deletions

View File

@ -196,20 +196,17 @@ sign must be used (https://bugs.python.org/issue9334)""",
elif not args.clone_mode: # if neather -p nor -c provided, use -p
args.west_path = west_top
def execute_command(command_args, stdin=None, input=None, stdout=None, stderr=None,
capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None,
errors=None, text=None, env=None, universal_newlines=None):
"""[summary] Provides wrapper for subprocess.run (matches its signature) that prints
def execute_command(*run_args, **run_kwargs):
"""[summary] Provides wrapper for subprocess.run that prints
command executed when 'more verbose' verbosity level is set."""
if args.verbose >= 0:
cwd = run_kwargs.get('cwd')
command_args = run_args[0]
print_cwd = f"In dir: {cwd}" if cwd else f"in current dir: {os.getcwd()}"
print_args = shlex.join(command_args) if isinstance(command_args, list) else command_args
print(f"{print_cwd}; running command: {print_args}", flush=True)
return subprocess.run(args=command_args, stdin=stdin, input=input, stdout=stdout,
stderr=stderr, capture_output=capture_output, shell=shell, cwd=cwd, timeout=timeout,
check=check, encoding=encoding, errors=errors, text=text, env=env,
universal_newlines=universal_newlines)
return subprocess.run(*run_args, **run_kwargs)
def show_installed_files():
"""[summary] Scans output directory building binary tree from files and folders