From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Warren Date: Thu, 7 Jul 2016 11:07:34 -0600 Subject: [U-Boot] [PATCH 08/14] test/py: Add an option to execute a string containing a command In-Reply-To: <1467560446-10628-9-git-send-email-sjg@chromium.org> References: <1467560446-10628-1-git-send-email-sjg@chromium.org> <1467560446-10628-9-git-send-email-sjg@chromium.org> Message-ID: <577E8C56.6010009@wwwdotorg.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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.