[Kimchi-devel] [PATCH] [WoK] utils.py: run_command runs in an en_US environment by default

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Tue Jan 12 00:43:56 UTC 2016


Reviewed by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>

On 11-01-2016 19:09, dhbarboza82 at gmail.com wrote:
> From: Daniel Henrique Barboza <dhbarboza82 at gmail.com>
>
> This requirement started in a fixed Gingerbase bug (#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 <dhbarboza82 at gmail.com>
> ---
>   src/wok/utils.py | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/src/wok/utils.py b/src/wok/utils.py
> index 05574d7..af534ec 100644
> --- a/src/wok/utils.py
> +++ b/src/wok/utils.py
> @@ -136,7 +136,8 @@ def import_module(module_name, class_name=''):
>       return __import__(module_name, globals(), locals(), [class_name])
>
>
> -def run_command(cmd, timeout=None, silent=False, tee=None):
> +def run_command(cmd, timeout=None, silent=False, tee=None,
> +                env_vars=None):
>       """
>       cmd is a sequence of command arguments.
>       timeout is a float number in seconds.
> @@ -184,9 +185,15 @@ def run_command(cmd, timeout=None, silent=False, tee=None):
>       timer = None
>       timeout_flag = [False]
>
> +    if env_vars is None:
> +        env_vars = os.environ.copy()
> +        env_vars['LC_ALL'] = 'C'
> +    elif env_vars.get('LC_ALL') is None:
> +        env_vars['LC_ALL'] = 'C'
> +
>       try:
>           proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> -                                stderr=subprocess.PIPE)
> +                                stderr=subprocess.PIPE, env=env_vars)
>           if timeout is not None:
>               timer = Timer(timeout, kill_proc, [proc, timeout_flag])
>               timer.setDaemon(True)
>

-- 
Jose Ricardo Ziviani
-----------------------------
Software Engineer
Linux Technology Center - IBM




More information about the Kimchi-devel mailing list