From 94813cea3c747f402a5a46f1b58936c0f232413e Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Mon, 28 Oct 2024 18:20:24 +0100 Subject: [PATCH] refs #1059 add ogGetCaller() --- client/lib/engine/bin/SystemLib.py | 35 ++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/client/lib/engine/bin/SystemLib.py b/client/lib/engine/bin/SystemLib.py index 999dd33..f168dc8 100644 --- a/client/lib/engine/bin/SystemLib.py +++ b/client/lib/engine/bin/SystemLib.py @@ -117,16 +117,33 @@ def ogExecAndLog(*args): # Salida de error del comando ejecutado. return subprocess.PIPESTATUS[0] +#/** +# ogGetCaller +#@brief Devuelve nombre del programa o script ejecutor (padre). +#@return str_name - Nombre del programa ejecutor. +#*/ def ogGetCaller(): - # Obtener el nombre del programa o del script que ha llamado al proceso actual. - output = subprocess.check_output(["ps", "hp", str(os.getppid()), "-o", "args"]).decode("utf-8") - lines = output.split("\n") - caller = "" - for line in lines: - if "bash" in line and line.split()[1] != "": - caller = line.split()[1] - else: - caller = line.split()[0].lstrip("-") + if 'COLUMNS' in os.environ: + cols = os.environ['COLUMNS'] + else: + cols = None + + lines = subprocess.run (["ps", "hp", str(os.getppid()), "-o", "args"], capture_output=True, text=True).stdout.splitlines() + if 0 == len (lines): + return '' + + line = lines[0] + words = line.split() + if "bash" in line and len(words)>1: + caller = words[1] + else: + caller = words[0].lstrip("-") + + if cols is None: + del (os.environ['COLUMNS']) + else: + os.environ['COLUMNS'] = cols + return os.path.basename(caller) def ogHelp(*args):