[Kimchi-devel] [PATCH 1/3] Add the env parameter to run_command.
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Mon Apr 27 15:19:00 UTC 2015
On 27-04-2015 11:48, Crístian Viana wrote:
> The patch looks nice, but could you provide us a scenario where this
> patch is needed? In which situation are you trying to run a command and
> you need to specify a different set of environment variables other than
> the default ones (i.e. the env inherited by the main process)? I
> couldn't figure this out by reading the patch's description.
>
> On Fri, Apr 17, 2015 at 4:29 PM Jose Ricardo Ziviani
> <joserz at linux.vnet.ibm.com <mailto:joserz at linux.vnet.ibm.com>> wrote:
>
> - The called may want to pass a custom environment variable to
> run_command and now this is possible with this new parameter.
>
> Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com
> <mailto:joserz at linux.vnet.ibm.com>>
> ---
> src/kimchi/utils.py | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
> index d71338a..2017cbe 100644
> --- a/src/kimchi/utils.py
> +++ b/src/kimchi/utils.py
> @@ -165,11 +165,12 @@ def check_url_path(path):
> return True
>
>
> -def run_command(cmd, timeout=None):
> +def run_command(cmd, timeout=None, env=None):
> """
> cmd is a sequence of command arguments.
> timeout is a float number in seconds.
> timeout default value is None, means command run without timeout.
> + env is the environment variable passed to the command.
> """
> # subprocess.kill() can leave descendants running
> # and halting the execution. Using psutil to
> @@ -193,7 +194,8 @@ def run_command(cmd, timeout=None):
>
> try:
> proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
> - stderr=subprocess.PIPE)
> + stderr=subprocess.PIPE,
> + env=env)
> if timeout is not None:
> timer = Timer(timeout, kill_proc, [proc, timeout_flag])
> timer.setDaemon(True)
> --
> 1.9.1
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org <mailto:Kimchi-devel at ovirt.org>
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>
Hello Crístian!
Sorry, I removed this commit from V2 on because it turned out to be not
necessary. However, in this particular case, I was looking for a string
("running") printed in stdout by nmcli. Passing LANG=C to environment I
make sure that I'll receive the string in the program's primary
language, not a possible translated version.
--
Jose Ricardo Ziviani
-----------------------------
Software Engineer
Linux Technology Center - IBM
More information about the Kimchi-devel
mailing list