refs #1093 rebuild ogListSoftware
parent
afec1aad2e
commit
9a1c90234e
|
@ -137,64 +137,64 @@ def ogListHardwareInfo():
|
|||
return f"{output}\n{firmware}\n{lshw_output}"
|
||||
|
||||
def ogListSoftware(disk, partition):
|
||||
# Error si no se reciben 2 parametros
|
||||
if disk is None or partition is None:
|
||||
SystemLib.ogRaiseError("OG_ERR_FORMAT")
|
||||
return
|
||||
SystemLib.ogRaiseError(ogGlobals.OG_ERR_FORMAT)
|
||||
return []
|
||||
|
||||
# Obtener tipo de sistema de archivos y montarlo
|
||||
mnt_dir = FileSystemLib.ogMount(disk, partition)
|
||||
os_type = ogGetOsType(disk, partition)
|
||||
|
||||
# Ficheros temporales
|
||||
apps_file = tempfile.NamedTemporaryFile(delete=False)
|
||||
tmp_file = tempfile.NamedTemporaryFile(delete=False)
|
||||
apps_file = tempfile.NamedTemporaryFile(delete=False, mode="w+")
|
||||
tmp_file = tempfile.NamedTemporaryFile(delete=False, mode="w+")
|
||||
apps = []
|
||||
|
||||
try:
|
||||
if os_type == "Linux":
|
||||
# Procesar paquetes dpkg
|
||||
pkg_dir = os.path.join(mnt_dir, "var/lib/dpkg")
|
||||
if os.path.exists(pkg_dir):
|
||||
with open(os.path.join(pkg_dir, "status"), "r") as status_file:
|
||||
for line in status_file:
|
||||
# Process lines to extract software info
|
||||
pass
|
||||
# Procesar paquetes RPM
|
||||
status_file = os.path.join(pkg_dir, "status")
|
||||
if os.path.exists(status_file):
|
||||
with open(status_file, "r") as f:
|
||||
pkg, ver = None, None
|
||||
for line in f:
|
||||
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")
|
||||
if os.path.exists(pkg_dir):
|
||||
# Execute rpm command if available
|
||||
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:
|
||||
# Compatibility mode for older systems
|
||||
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
|
||||
SystemLib.ogEcho("session", "error", "The rpm command is not available.")
|
||||
|
||||
pass
|
||||
|
||||
else:
|
||||
SystemLib.ogRaiseError("OG_ERR_NOTOS", disk, partition)
|
||||
SystemLib.ogRaiseError(ogGlobals.OG_ERR_NOTOS, disk, partition)
|
||||
return []
|
||||
|
||||
finally:
|
||||
# Eliminar archivos temporales
|
||||
apps_file.close()
|
||||
tmp_file.close()
|
||||
os.remove(apps_file.name)
|
||||
os.remove(tmp_file.name)
|
||||
|
||||
# Mostrar sistema operativo y aplicaciones
|
||||
ogGetOsVersion(disk, partition)
|
||||
with open(apps_file.name, "r") as apps:
|
||||
for line in sorted(set(apps.readlines())):
|
||||
print(line.strip())
|
||||
os_version = ogGetOsVersion(disk, partition)
|
||||
print(f"Operative System: {os_version}")
|
||||
|
||||
return sorted(set(apps))
|
||||
|
||||
def ogGetOsVersion(ndisk, nfilesys):
|
||||
# Variables locales.
|
||||
|
|
Loading…
Reference in New Issue