mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
target: Add Target.execute(force_locale='C') parameter
To avoid locale-specific variations in the output of commands, set LC_ALL=C by default. This can be disabled by using None, or set to another locale.
This commit is contained in:
parent
ea19235aed
commit
9c86174ff5
@ -385,10 +385,19 @@ class Target(object):
|
|||||||
# execution
|
# execution
|
||||||
|
|
||||||
def execute(self, command, timeout=None, check_exit_code=True,
|
def execute(self, command, timeout=None, check_exit_code=True,
|
||||||
as_root=False, strip_colors=True, will_succeed=False):
|
as_root=False, strip_colors=True, will_succeed=False,
|
||||||
|
force_locale='C'):
|
||||||
|
|
||||||
|
# Force the locale if necessary for more predictable output
|
||||||
|
if force_locale:
|
||||||
|
# Use an explicit export so that the command is allowed to be any
|
||||||
|
# shell statement, rather than just a command invocation
|
||||||
|
command = 'export LC_ALL={} && {}'.format(quote(force_locale), command)
|
||||||
|
|
||||||
# Ensure to use deployed command when availables
|
# Ensure to use deployed command when availables
|
||||||
if self.executables_directory:
|
if self.executables_directory:
|
||||||
command = "PATH={}:$PATH && {}".format(self.executables_directory, command)
|
command = "PATH={}:$PATH && {}".format(self.executables_directory, command)
|
||||||
|
|
||||||
return self.conn.execute(command, timeout=timeout,
|
return self.conn.execute(command, timeout=timeout,
|
||||||
check_exit_code=check_exit_code, as_root=as_root,
|
check_exit_code=check_exit_code, as_root=as_root,
|
||||||
strip_colors=strip_colors, will_succeed=will_succeed)
|
strip_colors=strip_colors, will_succeed=will_succeed)
|
||||||
|
@ -232,7 +232,7 @@ Target
|
|||||||
:param timeout: timeout (in seconds) for the transfer; if the transfer does
|
:param timeout: timeout (in seconds) for the transfer; if the transfer does
|
||||||
not complete within this period, an exception will be raised.
|
not complete within this period, an exception will be raised.
|
||||||
|
|
||||||
.. method:: Target.execute(command [, timeout [, check_exit_code [, as_root [, strip_colors [, will_succeed]]]]])
|
.. method:: Target.execute(command [, timeout [, check_exit_code [, as_root [, strip_colors [, will_succeed [, force_locale]]]]]])
|
||||||
|
|
||||||
Execute the specified command on the target device and return its output.
|
Execute the specified command on the target device and return its output.
|
||||||
|
|
||||||
@ -252,6 +252,9 @@ Target
|
|||||||
will make the method always raise an instance of a subclass of
|
will make the method always raise an instance of a subclass of
|
||||||
:class:`DevlibTransientError` when the command fails, instead of a
|
:class:`DevlibTransientError` when the command fails, instead of a
|
||||||
:class:`DevlibStableError`.
|
:class:`DevlibStableError`.
|
||||||
|
:param force_locale: Prepend ``LC_ALL=<force_locale>`` in front of the
|
||||||
|
command to get predictable output that can be more safely parsed.
|
||||||
|
If ``None``, no locale is prepended.
|
||||||
|
|
||||||
.. method:: Target.background(command [, stdout [, stderr [, as_root]]])
|
.. method:: Target.background(command [, stdout [, stderr [, as_root]]])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user