Skip to content

Commit 996b853

Browse files
danielhbalinefm
authored andcommitted
utils.py: run_command runs in an en_US environment by default
This requirement started in a fixed Gingerbase bug (kimchi-project#18) that reported lscpu problems when running in a French environment. The output was being translated to french and breaking the parsing made by the backend. This is such a powder keg for all the plug-ins that I believe this patch is justified. Instead of forcing en_US language by using subprocess.Popen and setting the env, this is how run_command will behave now: - A new optional attribute, env_vars, was added. As the name suggests, it allows the setup of the environment variables to run the command. - If env_vars is not set, run_command will copy the current environment variables and set the language to the default (en_US) by setting LC_ALL='C' variable. As of now, this is the case of all the existing run_command calls in the code for all WoK plug-ins. No behavior change will happen. - If env_vars is set, but the LC_ALL var isn't, run_command will set it to 'C' and force the default language. - If env_vars is set and LC_ALL is also set, run_command will not touch it and will run with env_vars as is. This allows the caller to set the language at will. Signed-off-by: Daniel Henrique Barboza <[email protected]>
1 parent 78cd1b3 commit 996b853

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: src/wok/utils.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Project Wok
33
#
4-
# Copyright IBM, Corp. 2013-2015
4+
# Copyright IBM, Corp. 2013-2016
55
#
66
# Code derived from Project Kimchi
77
#
@@ -136,7 +136,8 @@ def import_module(module_name, class_name=''):
136136
return __import__(module_name, globals(), locals(), [class_name])
137137

138138

139-
def run_command(cmd, timeout=None, silent=False, tee=None):
139+
def run_command(cmd, timeout=None, silent=False, tee=None,
140+
env_vars=None):
140141
"""
141142
cmd is a sequence of command arguments.
142143
timeout is a float number in seconds.
@@ -184,9 +185,15 @@ def tee_log(msg=None, log_file=None):
184185
timer = None
185186
timeout_flag = [False]
186187

188+
if env_vars is None:
189+
env_vars = os.environ.copy()
190+
env_vars['LC_ALL'] = 'C'
191+
elif env_vars.get('LC_ALL') is None:
192+
env_vars['LC_ALL'] = 'C'
193+
187194
try:
188195
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
189-
stderr=subprocess.PIPE)
196+
stderr=subprocess.PIPE, env=env_vars)
190197
if timeout is not None:
191198
timer = Timer(timeout, kill_proc, [proc, timeout_flag])
192199
timer.setDaemon(True)

0 commit comments

Comments
 (0)