From f896f680b6e231f31c8af704fc02d7496d4f7040 Mon Sep 17 00:00:00 2001 From: Douglas RAILLARD Date: Tue, 3 Sep 2019 12:23:18 +0100 Subject: [PATCH] lisa.target: Force LC_ALL=C by default for Target.execute() LC_ALL=C eliminates local variability on command outputs (translations etc), so they can be more safely parsed. --- lisa/target.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lisa/target.py b/lisa/target.py index 268b6e928..02e16a58b 100644 --- a/lisa/target.py +++ b/lisa/target.py @@ -717,6 +717,19 @@ class Target(Loggable, HideExekallID, ExekallTaggable, Configurable): self.target.install(tool) self._installed_tools.add(tool) + def execute(self, cmd, *args, force_local='C', **kwargs): + """ + Call :meth:`devlib.Target.execute` with all the arguments forwarded. + + :param force_local: Prefix the command with ``LC_ALL=`` so that + the commands execute with a known local, that can be expected to be + the same in all environments. + :type force_local: str or None + """ + if force_local: + cmd = 'LC_ALL={} {}'.format(shlex.quote(force_local), cmd) + + return self.target.execute(cmd, *args, **kwargs) @contextlib.contextmanager def freeze_userspace(self): -- GitLab