[U-Boot] [PATCH 08/14] test/py: Add an option to execute a string containing a command
Stephen Warren
swarren at wwwdotorg.org
Thu Jul 7 19:07:34 CEST 2016
On 07/03/2016 09:40 AM, Simon Glass wrote:
> It is sometimes inconvenient to convert a string into a list for execution
> with run_and_log(). Provide a helper function to do this.
> diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
> +def cmd(u_boot_console, cmd_str):
> + """Run a single command string and log its output.
> +
> + Args:
> + u_boot_console: A console connection to U-Boot.
> + cmd: The command to run, as a string.
> +
> + Returns:
> + The output as a string.
> + """
Thinking about this more: I believe the Pythonic way to do this would be
to extend the existing run_and_log() to support the cmd parameter being
either an array, or a string; I think something like just adding the
following at the start of run_and_log():
if isinstance(cmd, str):
cmd = str.split()
This would also allow other higher-order functions like your later
run_command_list() to take either a list of argv[] or a list of strings
(or even a mixture), without having to code multiple versions of the
higher level functions for the different cases.
More information about the U-Boot
mailing list