refs #1093 the call to ogListSoftware is optimized
parent
cd6f15d3b6
commit
61fb90d033
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
|
||||
import SystemLib
|
||||
import InventoryLib
|
||||
import NetLib
|
||||
|
@ -9,34 +9,39 @@ import ogGlobals
|
|||
|
||||
PROG = os.path.basename(__file__)
|
||||
REDUCED = "no"
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "-r":
|
||||
REDUCED = "yes"
|
||||
sys.argv.pop(1)
|
||||
|
||||
# Validar argumentos
|
||||
if len(sys.argv) != 3:
|
||||
SystemLib.ogRaiseError(ogGlobals.OG_ERR_FORMAT, f"{ogGlobals.MSG_FORMAT}: {PROG} ndisco nparticion")
|
||||
SystemLib.ogRaiseError("session", ogGlobals.OG_ERR_FORMAT, f"{ogGlobals.MSG_FORMAT}: {PROG} ndisco nparticion")
|
||||
sys.exit(1)
|
||||
|
||||
# Directorio del servidor donde se exportan los ficheros de registro.
|
||||
SERVERLOGDIR = subprocess.run(
|
||||
["awk", "-v", f"d={ogGlobals.OGLOG}", 'BEGIN {FS="[: ]"} {if ($4==d) dir=$2} END {print dir}'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
|
||||
# Fichero de listado: soft-IP-ndisco-npart
|
||||
# Nombre del archivo de listado
|
||||
SOFTFILE = f"soft-{NetLib.ogGetIpAddress()}-{sys.argv[1]}-{sys.argv[2]}"
|
||||
# Redirigir salida al fichero de listado.
|
||||
if REDUCED == "no":
|
||||
if subprocess.run(["ogListSoftware", sys.argv[1], sys.argv[2]], stdout=open(f"{ogGlobals.OGLOG}/{SOFTFILE}", "w")).returncode != 0:
|
||||
sys.exit(1)
|
||||
else:
|
||||
if subprocess.run(["ogListSoftware", sys.argv[1], sys.argv[2]], stdout=subprocess.PIPE).returncode == 0:
|
||||
with open(f"{ogGlobals.OGLOG}/{SOFTFILE}", "w") as f:
|
||||
f.write(subprocess.run(["egrep", "-v", "\(KB[0-9]{6}\)"], input=subprocess.PIPE).stdout.decode())
|
||||
else:
|
||||
sys.exit(1)
|
||||
softfile_path = os.path.join(ogGlobals.OGLOG, SOFTFILE)
|
||||
|
||||
# Salid: camino del fichero de listado en el servidor de repositorio.
|
||||
print(f"{ogGlobals.OGLOG}/{SOFTFILE}")
|
||||
try:
|
||||
# Generar listado de software con InventoryLib.ogListSoftware
|
||||
software_list = InventoryLib.ogListSoftware(int(sys.argv[1]), int(sys.argv[2]))
|
||||
|
||||
if REDUCED == "no":
|
||||
# Escribir el listado completo al archivo
|
||||
with open(softfile_path, "w") as f:
|
||||
for line in software_list:
|
||||
f.write(f"{line}\n")
|
||||
else:
|
||||
# Filtrar parches de Windows (KBxxxxxx) y guardar
|
||||
filtered_list = [line for line in software_list if "(KB" not in line]
|
||||
with open(softfile_path, "w") as f:
|
||||
for line in filtered_list:
|
||||
f.write(f"{line}\n")
|
||||
|
||||
print(softfile_path)
|
||||
|
||||
except Exception as e:
|
||||
# Manejar errores
|
||||
SystemLib.ogRaiseError("session", ogGlobals.OG_ERR_FORMAT, f"Error al generar el listado de software: {e}")
|
||||
sys.exit(1)
|
Loading…
Reference in New Issue