47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import os
|
|
import sys
|
|
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
|
|
|
import SystemLib
|
|
import InventoryLib
|
|
import NetLib
|
|
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("session", ogGlobals.OG_ERR_FORMAT, f"{ogGlobals.MSG_FORMAT}: {PROG} ndisco nparticion")
|
|
sys.exit(1)
|
|
|
|
# Nombre del archivo de listado
|
|
SOFTFILE = f"soft-{NetLib.ogGetIpAddress()}-{sys.argv[1]}-{sys.argv[2]}"
|
|
softfile_path = os.path.join(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) |