refs #1099 The syntax for calling libraries into InventoryLib.py has been modified
parent
d46ab35bd6
commit
2d94e3742e
|
@ -8,20 +8,18 @@ import re
|
|||
import json
|
||||
import shutil
|
||||
import sqlite3
|
||||
from SystemLib import ogMount, ogGetOsType, ogRaiseError, ogHelp, ogGetOsVersion, ogGetHivePath, ogListRegistryKeys, ogGetRegistryValue, ogGetIpAddress
|
||||
|
||||
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
||||
from SystemLib import ogEcho
|
||||
#from Disklib import ogDiskToDev
|
||||
#from engine.FileLib import *
|
||||
#from engine.RegistryLib import *
|
||||
#from engine.FileSystemLib import *
|
||||
import SystemLib
|
||||
import ogGlobals
|
||||
import FileLib
|
||||
import RegistryLib
|
||||
import FileSystemLib
|
||||
|
||||
MSG_HARDWAREINVENTORY = "Inventario de hardware de la máquina"
|
||||
|
||||
def ogGetArch():
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
||||
ogHelp(sys.argv[0], sys.argv[0], sys.argv[0] + " => x86_64")
|
||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0], sys.argv[0] + " => x86_64")
|
||||
return
|
||||
|
||||
if platform.machine().endswith("64"):
|
||||
|
@ -32,23 +30,23 @@ def ogGetArch():
|
|||
def ogGetOsType():
|
||||
# Si se solicita, mostrar ayuda.
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
||||
ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_npartition", sys.argv[0] + " 1 2 => Linux")
|
||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_npartition", sys.argv[0] + " 1 2 => Linux")
|
||||
return
|
||||
ogGetOsVersion(sys.argv[1:]).split(':')[0]
|
||||
|
||||
def ogGetOsUuid():
|
||||
# Si se solicita, mostrar ayuda.
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
||||
ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_nfilesys", sys.argv[0] + " 1 2 => 540e47c6-8e78-4178-aa46-042e4803fb16")
|
||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_nfilesys", sys.argv[0] + " 1 2 => 540e47c6-8e78-4178-aa46-042e4803fb16")
|
||||
return
|
||||
|
||||
# Error si no se reciben 2 parametros.
|
||||
if len(sys.argv) != 3:
|
||||
ogRaiseError(OG_ERR_FORMAT)
|
||||
SystemLib.ogRaiseError(OG_ERR_FORMAT)
|
||||
return
|
||||
|
||||
# Montar la particion, si no lo estaba previamente.
|
||||
MNTDIR = ogMount(sys.argv[1], sys.argv[2])
|
||||
MNTDIR = FileSystemLib.ogMount(sys.argv[1], sys.argv[2])
|
||||
if not MNTDIR:
|
||||
return
|
||||
|
||||
|
@ -60,13 +58,13 @@ def ogGetOsUuid():
|
|||
print(uuid)
|
||||
elif os_type == "Windows":
|
||||
# Leer identificador en clave de registro.
|
||||
uuid = ogGetRegistryValue(MNTDIR, "SOFTWARE", "\\Microsoft\\Cryptography\\MachineGuid")
|
||||
uuid = Registry.ogGetRegistryValue(MNTDIR, "SOFTWARE", "\\Microsoft\\Cryptography\\MachineGuid")
|
||||
print(uuid)
|
||||
|
||||
def ogGetSerialNumber():
|
||||
# Si se solicita, mostrar ayuda.
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
||||
ogHelp(sys.argv[0], sys.argv[0], sys.argv[0] + " => 123456")
|
||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0], sys.argv[0] + " => 123456")
|
||||
return
|
||||
|
||||
# Obtener nº de serie (ignorar los no especificados).
|
||||
|
@ -141,12 +139,12 @@ def ogListHardwareInfo():
|
|||
def ogListSoftware(disk, partition):
|
||||
# Error si no se reciben 2 parametros
|
||||
if disk is None or partition is None:
|
||||
og_raise_error("OG_ERR_FORMAT")
|
||||
SystemLib.ogRaiseError("OG_ERR_FORMAT")
|
||||
return
|
||||
|
||||
# Obtener tipo de sistema de archivos y montarlo
|
||||
mnt_dir = og_mount(disk, partition)
|
||||
os_type = og_get_os_type(disk, partition)
|
||||
mnt_dir = FileSystemLib.ogMount(disk, partition)
|
||||
os_type = ogGetOsType(disk, partition)
|
||||
|
||||
# Ficheros temporales
|
||||
apps_file = tempfile.NamedTemporaryFile(delete=False)
|
||||
|
@ -174,17 +172,17 @@ def ogListSoftware(disk, partition):
|
|||
pass
|
||||
elif os_type == "Windows":
|
||||
# Procesar aplicaciones instaladas en Windows
|
||||
hive_path = og_get_hive_path(mnt_dir, "software")
|
||||
hive_path = Registry.ogGetHivePath(mnt_dir, "software")
|
||||
if hive_path:
|
||||
subprocess.run(["hivexregedit", "--unsafe-printable-strings", "--export", hive_path, '\Microsoft\Windows\CurrentVersion\Uninstall'], stdout=tmp_file)
|
||||
elif os_type == "MacOS":
|
||||
elif osType == "MacOS":
|
||||
# Procesar aplicaciones instaladas en MacOS
|
||||
pass
|
||||
elif os_type == "BSD":
|
||||
elif osType == "BSD":
|
||||
# Procesar aplicaciones instaladas en FreeBSD
|
||||
pass
|
||||
else:
|
||||
og_raise_error("OG_ERR_NOTOS", disk, partition)
|
||||
SystemLib.ogRaiseError("OG_ERR_NOTOS", disk, partition)
|
||||
finally:
|
||||
# Eliminar archivos temporales
|
||||
apps_file.close()
|
||||
|
@ -193,30 +191,30 @@ def ogListSoftware(disk, partition):
|
|||
os.remove(tmp_file.name)
|
||||
|
||||
# Mostrar sistema operativo y aplicaciones
|
||||
og_get_os_version(disk, partition)
|
||||
ogGetOsVersion(disk, partition)
|
||||
with open(apps_file.name, "r") as apps:
|
||||
for line in sorted(set(apps.readlines())):
|
||||
print(line.strip())
|
||||
|
||||
def ogGetOsVersion(ndisk, nfilesys):
|
||||
# Variables locales.
|
||||
MNTDIR = ogMount(ndisk, nfilesys)
|
||||
MNTDIR = FileSystemLib.ogMount(ndisk, nfilesys)
|
||||
TYPE = ""
|
||||
VERSION = ""
|
||||
IS64BIT = ""
|
||||
|
||||
# Si se solicita, mostrar ayuda.
|
||||
if len(sys.argv) > 1 and sys.argv[1] == "help":
|
||||
ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_nfilesys", sys.argv[0] + " 1 2 => Linux:Ubuntu precise (12.04 LTS) 64 bits")
|
||||
SystemLib.ogHelp(sys.argv[0], sys.argv[0] + " int_ndisk int_nfilesys", sys.argv[0] + " 1 2 => Linux:Ubuntu precise (12.04 LTS) 64 bits")
|
||||
return
|
||||
|
||||
# Error si no se reciben 2 parametros.
|
||||
if len(sys.argv) != 3:
|
||||
ogRaiseError(OG_ERR_FORMAT)
|
||||
SystemLib.ogRaiseError(OG_ERR_FORMAT)
|
||||
return
|
||||
|
||||
# Montar la particion, si no lo estaba previamente.
|
||||
MNTDIR = ogMount(sys.argv[1], sys.argv[2])
|
||||
MNTDIR = FileSystemLib.ogMount(sys.argv[1], sys.argv[2])
|
||||
if not MNTDIR:
|
||||
return
|
||||
|
||||
|
@ -301,7 +299,7 @@ def ogGetOsVersion(ndisk, nfilesys):
|
|||
lines = output.split("\n")
|
||||
if len(lines) == 2:
|
||||
VERSION = lines[1].strip()
|
||||
if ogGetRegistryValue(MNTDIR, "SOFTWARE", "\\Microsoft\\Windows\\CurrentVersion\\ProgramW6432Dir"):
|
||||
if Registry.ogGetRegistryValue(MNTDIR, "SOFTWARE", "\\Microsoft\\Windows\\CurrentVersion\\ProgramW6432Dir"):
|
||||
IS64BIT = "64 bits"
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
@ -309,9 +307,9 @@ def ogGetOsVersion(ndisk, nfilesys):
|
|||
# Para cargador Windows: buscar versión en fichero BCD (basado en os-prober).
|
||||
if not VERSION:
|
||||
TYPE = "WinLoader"
|
||||
FILE = ogGetPath(MNTDIR, "boot", "bcd")
|
||||
FILE = FileLib.ogGetPath(MNTDIR, "boot", "bcd")
|
||||
if not FILE:
|
||||
FILE = ogGetPath(MNTDIR, "EFI", "Microsoft", "boot", "bcd")
|
||||
FILE = FileLib.ogGetPath(MNTDIR, "EFI", "Microsoft", "boot", "bcd")
|
||||
if FILE:
|
||||
for DISTRIB in ["Windows Recovery", "Windows Boot"]:
|
||||
with open(FILE, "rb") as f:
|
||||
|
|
Loading…
Reference in New Issue