refs #1093 rebuild ogListSoftware
parent
afec1aad2e
commit
9a1c90234e
|
@ -137,64 +137,64 @@ def ogListHardwareInfo():
|
||||||
return f"{output}\n{firmware}\n{lshw_output}"
|
return f"{output}\n{firmware}\n{lshw_output}"
|
||||||
|
|
||||||
def ogListSoftware(disk, partition):
|
def ogListSoftware(disk, partition):
|
||||||
# Error si no se reciben 2 parametros
|
|
||||||
if disk is None or partition is None:
|
if disk is None or partition is None:
|
||||||
SystemLib.ogRaiseError("OG_ERR_FORMAT")
|
SystemLib.ogRaiseError(ogGlobals.OG_ERR_FORMAT)
|
||||||
return
|
return []
|
||||||
|
|
||||||
# Obtener tipo de sistema de archivos y montarlo
|
|
||||||
mnt_dir = FileSystemLib.ogMount(disk, partition)
|
mnt_dir = FileSystemLib.ogMount(disk, partition)
|
||||||
os_type = ogGetOsType(disk, partition)
|
os_type = ogGetOsType(disk, partition)
|
||||||
|
|
||||||
# Ficheros temporales
|
apps_file = tempfile.NamedTemporaryFile(delete=False, mode="w+")
|
||||||
apps_file = tempfile.NamedTemporaryFile(delete=False)
|
tmp_file = tempfile.NamedTemporaryFile(delete=False, mode="w+")
|
||||||
tmp_file = tempfile.NamedTemporaryFile(delete=False)
|
apps = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if os_type == "Linux":
|
if os_type == "Linux":
|
||||||
# Procesar paquetes dpkg
|
|
||||||
pkg_dir = os.path.join(mnt_dir, "var/lib/dpkg")
|
pkg_dir = os.path.join(mnt_dir, "var/lib/dpkg")
|
||||||
if os.path.exists(pkg_dir):
|
status_file = os.path.join(pkg_dir, "status")
|
||||||
with open(os.path.join(pkg_dir, "status"), "r") as status_file:
|
if os.path.exists(status_file):
|
||||||
for line in status_file:
|
with open(status_file, "r") as f:
|
||||||
# Process lines to extract software info
|
pkg, ver = None, None
|
||||||
pass
|
for line in f:
|
||||||
# Procesar paquetes RPM
|
if line.startswith("Package:"):
|
||||||
|
pkg = line.split(":", 1)[1].strip()
|
||||||
|
elif line.startswith("Version:"):
|
||||||
|
ver = line.split(":", 1)[1].strip()
|
||||||
|
elif line.startswith("Status:") and "install" not in line:
|
||||||
|
pkg, ver = None, None
|
||||||
|
if pkg and ver:
|
||||||
|
apps.append(f"{pkg} {ver}")
|
||||||
|
pkg, ver = None, None
|
||||||
|
|
||||||
pkg_dir = os.path.join(mnt_dir, "var/lib/rpm")
|
pkg_dir = os.path.join(mnt_dir, "var/lib/rpm")
|
||||||
if os.path.exists(pkg_dir):
|
if os.path.exists(pkg_dir):
|
||||||
# Execute rpm command if available
|
|
||||||
if shutil.which("rpm"):
|
if shutil.which("rpm"):
|
||||||
subprocess.run(["rpm", "--dbpath", pkg_dir, "-qa", "--qf", "%{NAME} %{VERSION}\n"], stdout=apps_file)
|
result = subprocess.run(
|
||||||
|
["rpm", "--dbpath", pkg_dir, "-qa", "--qf", "%{NAME} %{VERSION}\n"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
if result.returncode == 0:
|
||||||
|
apps.extend(result.stdout.strip().splitlines())
|
||||||
else:
|
else:
|
||||||
# Compatibility mode for older systems
|
SystemLib.ogEcho("session", "error", "The rpm command is not available.")
|
||||||
pass
|
|
||||||
# Procesar otros tipos de paquetes (pacman, snap, flatpak, etc.)
|
|
||||||
pass
|
|
||||||
elif os_type == "Windows":
|
|
||||||
# Procesar aplicaciones instaladas en Windows
|
|
||||||
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 osType == "MacOS":
|
|
||||||
# Procesar aplicaciones instaladas en MacOS
|
|
||||||
pass
|
|
||||||
elif osType == "BSD":
|
|
||||||
# Procesar aplicaciones instaladas en FreeBSD
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
SystemLib.ogRaiseError("OG_ERR_NOTOS", disk, partition)
|
SystemLib.ogRaiseError(ogGlobals.OG_ERR_NOTOS, disk, partition)
|
||||||
|
return []
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# Eliminar archivos temporales
|
|
||||||
apps_file.close()
|
apps_file.close()
|
||||||
tmp_file.close()
|
tmp_file.close()
|
||||||
os.remove(apps_file.name)
|
os.remove(apps_file.name)
|
||||||
os.remove(tmp_file.name)
|
os.remove(tmp_file.name)
|
||||||
|
|
||||||
# Mostrar sistema operativo y aplicaciones
|
os_version = ogGetOsVersion(disk, partition)
|
||||||
ogGetOsVersion(disk, partition)
|
print(f"Operative System: {os_version}")
|
||||||
with open(apps_file.name, "r") as apps:
|
|
||||||
for line in sorted(set(apps.readlines())):
|
return sorted(set(apps))
|
||||||
print(line.strip())
|
|
||||||
|
|
||||||
def ogGetOsVersion(ndisk, nfilesys):
|
def ogGetOsVersion(ndisk, nfilesys):
|
||||||
# Variables locales.
|
# Variables locales.
|
||||||
|
|
Loading…
Reference in New Issue