refs #1093 the call to ogListSoftware is optimized

code-review
Antonio Guerrero 2024-11-13 00:01:32 -06:00
parent 61fb90d033
commit 381099dcc4
1 changed files with 0 additions and 6 deletions

View File

@ -14,26 +14,21 @@ if len(sys.argv) > 1 and sys.argv[1] == "-r":
REDUCED = "yes" REDUCED = "yes"
sys.argv.pop(1) sys.argv.pop(1)
# Validar argumentos
if len(sys.argv) != 3: if len(sys.argv) != 3:
SystemLib.ogRaiseError("session", 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) sys.exit(1)
# Nombre del archivo de listado
SOFTFILE = f"soft-{NetLib.ogGetIpAddress()}-{sys.argv[1]}-{sys.argv[2]}" SOFTFILE = f"soft-{NetLib.ogGetIpAddress()}-{sys.argv[1]}-{sys.argv[2]}"
softfile_path = os.path.join(ogGlobals.OGLOG, SOFTFILE) softfile_path = os.path.join(ogGlobals.OGLOG, SOFTFILE)
try: try:
# Generar listado de software con InventoryLib.ogListSoftware
software_list = InventoryLib.ogListSoftware(int(sys.argv[1]), int(sys.argv[2])) software_list = InventoryLib.ogListSoftware(int(sys.argv[1]), int(sys.argv[2]))
if REDUCED == "no": if REDUCED == "no":
# Escribir el listado completo al archivo
with open(softfile_path, "w") as f: with open(softfile_path, "w") as f:
for line in software_list: for line in software_list:
f.write(f"{line}\n") f.write(f"{line}\n")
else: else:
# Filtrar parches de Windows (KBxxxxxx) y guardar
filtered_list = [line for line in software_list if "(KB" not in line] filtered_list = [line for line in software_list if "(KB" not in line]
with open(softfile_path, "w") as f: with open(softfile_path, "w") as f:
for line in filtered_list: for line in filtered_list:
@ -42,6 +37,5 @@ try:
print(softfile_path) print(softfile_path)
except Exception as e: except Exception as e:
# Manejar errores
SystemLib.ogRaiseError("session", ogGlobals.OG_ERR_FORMAT, f"Error al generar el listado de software: {e}") SystemLib.ogRaiseError("session", ogGlobals.OG_ERR_FORMAT, f"Error al generar el listado de software: {e}")
sys.exit(1) sys.exit(1)