refs #1093 Script InventarioSoftware is optimized

code-review
Antonio Guerrero 2024-11-13 00:05:54 -06:00
parent 381099dcc4
commit c066725bce
1 changed files with 9 additions and 16 deletions

View File

@ -4,18 +4,14 @@ import shutil
import subprocess
import sys
sys.path.append('/opt/opengnsys/lib/engine/bin')
import ogGlobals
def main(arg1, arg2, dest_file):
start_time = time.time()
# Cargar la configuración del motor desde el archivo engine.cfg
og_engine_configurate = os.getenv('OGENGINECONFIGURATE')
if not og_engine_configurate:
with open('/opt/opengnsys/etc/engine.cfg') as f:
exec(f.read())
# Limpiar los archivos temporales usados como log para httpdlog
og_log_session = os.getenv('OGLOGSESSION')
og_log_command = os.getenv('OGLOGCOMMAND')
og_log_session = os.getenv(ogGlobals.OGLOGSESSION)
og_log_command = os.getenv(ogGlobals.OGLOGCOMMAND)
if og_log_session and og_log_command:
with open(og_log_session, 'w') as f:
f.write(" ")
@ -24,12 +20,10 @@ def main(arg1, arg2, dest_file):
with open(f"{og_log_command}.tmp", 'w') as f:
f.write(" ")
# Registrar el inicio de ejecución
msg_interface_start = os.getenv('MSG_INTERFACE_START')
msg_interface_start = os.getenv(ogGlobals.MSG_INTERFACE_START)
if msg_interface_start:
subprocess.run(['ogEcho', 'log', 'session', f"{msg_interface_start} {__file__} {arg1} {arg2}"])
# Ejecutar el script listSoftwareInfo y capturar el archivo de salida
try:
result = subprocess.run(
["python3", "/opt/opengnsys/scripts/listSoftwareInfo.py", arg1, arg2],
@ -37,15 +31,14 @@ def main(arg1, arg2, dest_file):
text=True,
check=True
)
file = result.stdout.strip() # Captura la salida del script
file = result.stdout.strip().splitlines()[-1]
except subprocess.CalledProcessError as e:
print(f"Error al ejecutar listSoftwareInfo: {e.stderr}")
sys.exit(e.returncode)
# Copiar el archivo resultante a dest_file
print(f"Copying:( {file} to {dest_file} )")
shutil.copy(file, dest_file)
# Registrar el tiempo de ejecución
elapsed_time = time.time() - start_time
msg_scripts_time_partial = os.getenv('MSG_SCRIPTS_TIME_PARTIAL')
if msg_scripts_time_partial:
@ -55,4 +48,4 @@ if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: python InventarioSoftware.py <arg1> <arg2> <dest_file>")
sys.exit(1)
main(sys.argv[1], sys.argv[2], sys.argv[3])
main(sys.argv[1], sys.argv[2], sys.argv[3])