refs #1099 The syntax for calling libraries has been modified

pull/1/head
Antonio Guerrero 2024-11-06 04:30:53 +00:00
parent 9953807e79
commit d46ab35bd6
12 changed files with 152 additions and 146 deletions

0
client/lib/engine/bin/CacheLib.py 100644 → 100755
View File

127
client/lib/engine/bin/DiskLib.py 100644 → 100755
View File

@ -7,8 +7,7 @@ from pathlib import Path
import ogGlobals
import SystemLib
print (">>>>>>>>>>>>>>>>>>>> Load ", __name__, " <<<<<<<<<<<<<<<<<<<<<<")
import CacheLib
def parted(*args):
parted_path = shutil.which("parted")
@ -33,13 +32,13 @@ def ogCreatePartitions(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogCreatePartitions', 'ogCreatePartitions int_ndisk str_parttype:int_partsize ...',
SystemLib.ogHelp('ogCreatePartitions', 'ogCreatePartitions int_ndisk str_parttype:int_partsize ...',
'ogCreatePartitions 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000')
return
# Error si no se reciben al menos 2 parámetros.
if len(args) < 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Nº total de sectores, para evitar desbordamiento (evitar redondeo).
@ -54,15 +53,15 @@ def ogCreatePartitions(*args):
ogCreateGptPartitions(*args)
return
elif PTTYPE != "MSDOS":
ogRaiseError(OG_ERR_PARTITION, PTTYPE)
SystemLib.ogRaiseError(OG_ERR_PARTITION, PTTYPE)
return
SECTORS = ogGetLastSector(ND)
# Se recalcula el nº de sectores del disco 1, si existe partición de caché.
CACHEPART = ogFindCache()
CACHEPART = CacheLib.ogFindCache()
if CACHEPART and ND == CACHEPART.split()[0]:
CACHESIZE = int(ogGetCacheSize()) * 2
CACHESIZE = int(CacheLib.ogGetCacheSize()) * 2
# Sector de inicio (la partición 1 empieza en el sector 63).
IODISCO = ogDiskToDev(ND)
@ -120,7 +119,7 @@ def ogCreatePartitions(*args):
os.remove(tmpsfdisk)
if CACHESIZE:
ogMountCache()
CacheLib.ogMountCache()
return 0
def ogCreateGptPartitions(*args):
@ -129,13 +128,13 @@ def ogCreateGptPartitions(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogCreateGptPartitions', 'ogCreateGptPartitions int_ndisk str_parttype:int_partsize ...',
SystemLib.ogHelp('ogCreateGptPartitions', 'ogCreateGptPartitions int_ndisk str_parttype:int_partsize ...',
'ogCreateGptPartitions 1 NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000')
return
# Error si no se reciben menos de 2 parámetros.
if len(args) < 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Nº total de sectores, para evitar desbordamiento (evitar redondeo).
@ -148,7 +147,7 @@ def ogCreateGptPartitions(*args):
SECTORS = ogGetLastSector(ND)
# Se recalcula el nº de sectores del disco si existe partición de caché.
CACHEPART = ogFindCache()
CACHEPART = CacheLib.ogFindCache()
if ND == CACHEPART.split()[0]:
CACHESIZE = int(ogGetCacheSize()) * 2
if CACHESIZE:
@ -172,7 +171,7 @@ def ogCreateGptPartitions(*args):
# Error si la partición es extendida (no válida en discos GPT).
if TYPE == "EXTENDED":
ogRaiseError(OG_ERR_PARTITION, "EXTENDED")
SystemLib.ogRaiseError(OG_ERR_PARTITION, "EXTENDED")
return
# Comprobar si existe la particion actual, capturamos su tamaño para ver si cambio o no
@ -191,7 +190,7 @@ def ogCreateGptPartitions(*args):
# Error si se supera el nº total de sectores.
if START > SECTORS:
ogRaiseError(OG_ERR_FORMAT, f"{START//2} > {SECTORS//2}")
SystemLib.ogRaiseError(OG_ERR_FORMAT, f"{START//2} > {SECTORS//2}")
return
PART += 1
@ -200,7 +199,7 @@ def ogCreateGptPartitions(*args):
# Desmontar los sistemas de archivos del disco antes de realizar las operaciones.
ogUnmountAll(ND)
if CACHESIZE:
ogUnmountCache()
CacheLib.ogUnmountCache()
# Si la tabla de particiones no es valida, volver a generarla.
ogCreatePartitionTable(ND)
@ -211,7 +210,7 @@ def ogCreateGptPartitions(*args):
subprocess.run(["partprobe", DISK], stderr=subprocess.DEVNULL)
if CACHESIZE:
ogMountCache()
CacheLib.ogMountCache()
return 0
def ogCreatePartitionTable(*args):
@ -220,7 +219,7 @@ def ogCreatePartitionTable(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogCreatePartitionTable', 'ogCreatePartitionTable int_ndisk [str_partype]',
SystemLib.ogHelp('ogCreatePartitionTable', 'ogCreatePartitionTable int_ndisk [str_partype]',
'ogCreatePartitionTable 1 GPT', 'ogCreatePartitionTable 1')
return
@ -230,7 +229,7 @@ def ogCreatePartitionTable(*args):
elif len(args) == 2:
CREATEPTT = args[1]
else:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Capturamos el tipo de tabla de particiones actual
@ -287,12 +286,12 @@ def ogDeletePartitionTable(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogDeletePartitionTable', 'ogDeletePartitionTable int_ndisk', 'ogDeletePartitionTable 1')
SystemLib.ogHelp('ogDeletePartitionTable', 'ogDeletePartitionTable int_ndisk', 'ogDeletePartitionTable 1')
return
# Error si no se reciben 1 parámetros.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obteniendo Identificador linux del disco.
@ -549,12 +548,12 @@ def ogGetDiskSize(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetDiskSize', 'ogGetDiskSize int_ndisk', 'ogGetDiskSize 1 => 244198584')
SystemLib.ogHelp('ogGetDiskSize', 'ogGetDiskSize int_ndisk', 'ogGetDiskSize 1 => 244198584')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obtener el tamaño del disco.
@ -574,12 +573,12 @@ def ogGetDiskType(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetDiskType', 'ogGetDiskType path_device', 'ogGetDiskType /dev/sdb => USB')
SystemLib.ogHelp('ogGetDiskType', 'ogGetDiskType path_device', 'ogGetDiskType /dev/sdb => USB')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obtener el driver del dispositivo de bloques.
@ -626,7 +625,7 @@ def ogGetLastSector(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp("ogGetLastSector", "ogGetLastSector int_ndisk [int_npart]",
SystemLib.ogHelp("ogGetLastSector", "ogGetLastSector int_ndisk [int_npart]",
"ogGetLastSector 1 => 488392064",
"ogGetLastSector 1 1 => 102400062")
return
@ -646,7 +645,7 @@ def ogGetLastSector(*args):
return
LASTSECTOR = subprocess.getoutput(f"sgdisk -p {DISK} | awk -v P='{args[1]}' '{{if ($1==P) print $3}}'")
else: # Error si se reciben más parámetros.
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
print(LASTSECTOR)
@ -658,12 +657,12 @@ def ogGetPartitionActive(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetPartitionActive', 'ogGetPartitionActive int_ndisk', 'ogGetPartitionActive 1 => 1')
SystemLib.ogHelp('ogGetPartitionActive', 'ogGetPartitionActive int_ndisk', 'ogGetPartitionActive 1 => 1')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Comprobar que el disco existe y listar su partición activa.
@ -681,12 +680,12 @@ def ogGetPartitionId(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetPartitionId', 'ogGetPartitionId int_ndisk int_npartition', 'ogGetPartitionId 1 1 => 7')
SystemLib.ogHelp('ogGetPartitionId', 'ogGetPartitionId int_ndisk int_npartition', 'ogGetPartitionId 1 1 => 7')
return
# Error si no se reciben 2 parámetros.
if len(args) != 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Detectar y mostrar el id. de tipo de partición.
@ -715,12 +714,12 @@ def ogGetPartitionSize(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetPartitionSize', 'ogGetPartitionSize int_ndisk int_npartition', 'ogGetPartitionSize 1 1 => 10000000')
SystemLib.ogHelp('ogGetPartitionSize', 'ogGetPartitionSize int_ndisk int_npartition', 'ogGetPartitionSize 1 1 => 10000000')
return
# Error si no se reciben 2 parámetros.
if len(args) != 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Devolver tamaño de partición, del volumen lógico o del sistema de archivos (para ZFS).
@ -741,12 +740,12 @@ def ogGetPartitionsNumber(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetPartitionsNumber', 'ogGetPartitionsNumber int_ndisk', 'ogGetPartitionsNumber 1 => 3')
SystemLib.ogHelp('ogGetPartitionsNumber', 'ogGetPartitionsNumber int_ndisk', 'ogGetPartitionsNumber 1 => 3')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Contar el número de veces que aparece el disco en su lista de particiones.
@ -776,12 +775,12 @@ def ogGetPartitionTableType(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetPartitionTableType', 'ogGetPartitionTableType int_ndisk', 'ogGetPartitionTableType 1 => MSDOS')
SystemLib.ogHelp('ogGetPartitionTableType', 'ogGetPartitionTableType int_ndisk', 'ogGetPartitionTableType 1 => MSDOS')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Sustituye n de disco por su dispositivo.
@ -815,12 +814,12 @@ def ogGetPartitionType(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogGetPartitionType', 'ogGetPartitionType int_ndisk int_npartition', 'ogGetPartitionType 1 1 => NTFS')
SystemLib.ogHelp('ogGetPartitionType', 'ogGetPartitionType int_ndisk int_npartition', 'ogGetPartitionType 1 1 => NTFS')
return
# Error si no se reciben 2 parámetros.
if len(args) != 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Detectar id. de tipo de partición y codificar al mnemónico.
@ -839,12 +838,12 @@ def ogHidePartition(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogHidePartition', 'ogHidePartition int_ndisk int_npartition', 'ogHidePartition 1 1')
SystemLib.ogHelp('ogHidePartition', 'ogHidePartition int_ndisk int_npartition', 'ogHidePartition 1 1')
return
# Error si no se reciben 2 parámetros.
if len(args) != 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obtener el dispositivo de la partición.
@ -865,7 +864,7 @@ def ogHidePartition(*args):
elif TYPE == "WINDOWS":
NEWTYPE = "WIN-RESERV"
else:
ogRaiseError(OG_ERR_PARTITION, TYPE)
SystemLib.ogRaiseError(OG_ERR_PARTITION, TYPE)
return
# Cambiar tipo de partición.
@ -978,7 +977,7 @@ def ogIsDiskLocked(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogIsDiskLocked', 'ogIsDiskLocked int_ndisk', 'if ogIsDiskLocked(1): ...')
SystemLib.ogHelp('ogIsDiskLocked', 'ogIsDiskLocked int_ndisk', 'if ogIsDiskLocked(1): ...')
return
# Falso, en caso de error.
@ -1002,12 +1001,12 @@ def ogListPartitions(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogListPartitions', 'ogListPartitions int_ndisk', 'ogListPartitions 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000')
SystemLib.ogHelp('ogListPartitions', 'ogListPartitions int_ndisk', 'ogListPartitions 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Procesar la salida de parted.
@ -1029,7 +1028,7 @@ def ogListPrimaryPartitions(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogListPrimaryPartitions', 'ogListPrimaryPartitions int_ndisk', 'ogListPrimaryPartitions 1 => NTFS:10000000 EXT3:5000000 EXTENDED:1000000')
SystemLib.ogHelp('ogListPrimaryPartitions', 'ogListPrimaryPartitions int_ndisk', 'ogListPrimaryPartitions 1 => NTFS:10000000 EXT3:5000000 EXTENDED:1000000')
return
PTTYPE = ogGetPartitionTableType(args[0])
@ -1052,7 +1051,7 @@ def ogListLogicalPartitions(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogListLogicalPartitions', 'ogListLogicalPartitions int_ndisk', 'ogListLogicalPartitions 1 => LINUX-SWAP:999998')
SystemLib.ogHelp('ogListLogicalPartitions', 'ogListLogicalPartitions int_ndisk', 'ogListLogicalPartitions 1 => LINUX-SWAP:999998')
return
PTTYPE = ogGetPartitionTableType(args[0])
@ -1071,12 +1070,12 @@ def ogLockDisk(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogLockDisk', 'ogLockDisk int_ndisk', 'ogLockDisk 1')
SystemLib.ogHelp('ogLockDisk', 'ogLockDisk int_ndisk', 'ogLockDisk 1')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obtener partición.
@ -1095,12 +1094,12 @@ def ogSetPartitionActive(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogSetPartitionActive', 'ogSetPartitionActive int_ndisk int_npartition', 'ogSetPartitionActive 1 1')
SystemLib.ogHelp('ogSetPartitionActive', 'ogSetPartitionActive int_ndisk int_npartition', 'ogSetPartitionActive 1 1')
return
# Error si no se reciben 2 parámetros.
if len(args) != 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Comprobar que el disco existe y activar la partición indicada.
@ -1122,12 +1121,12 @@ def ogSetPartitionId(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogSetPartitionId', 'ogSetPartitionId int_ndisk int_npartition hex_partid', 'ogSetPartitionId 1 1 7')
SystemLib.ogHelp('ogSetPartitionId', 'ogSetPartitionId int_ndisk int_npartition hex_partid', 'ogSetPartitionId 1 1 7')
return
# Error si no se reciben 3 parámetros.
if len(args) != 3:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Sustituye nº de disco y nº partición por su dispositivo.
@ -1140,7 +1139,7 @@ def ogSetPartitionId(*args):
# Error si el id. de partición no es hexadecimal.
ID = args[2].upper()
if not re.match("^[0-9A-F]+$", ID):
ogRaiseError(OG_ERR_OUTOFLIMIT, args[2])
SystemLib.ogRaiseError(OG_ERR_OUTOFLIMIT, args[2])
return
# Elección del tipo de partición.
@ -1150,14 +1149,14 @@ def ogSetPartitionId(*args):
elif PTTYPE == "MSDOS":
subprocess.run(["sfdisk", f"--id", DISK, args[1], ID], stderr=subprocess.DEVNULL)
else:
ogRaiseError(OG_ERR_OUTOFLIMIT, f"{args[0]},{PTTYPE}")
SystemLib.ogRaiseError(OG_ERR_OUTOFLIMIT, f"{args[0]},{PTTYPE}")
return
# MSDOS) Correcto si fdisk sin error o con error pero realiza Syncing
if subprocess.run(["partprobe", DISK], stderr=subprocess.DEVNULL).returncode == 0:
return
else:
ogRaiseError(OG_ERR_PARTITION, f"{args[0]},{args[1]},{args[2]}")
SystemLib.ogRaiseError(OG_ERR_PARTITION, f"{args[0]},{args[1]},{args[2]}")
return
def ogSetPartitionSize(*args):
@ -1168,12 +1167,12 @@ def ogSetPartitionSize(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogSetPartitionSize', 'ogSetPartitionSize int_ndisk int_npartition int_size', 'ogSetPartitionSize 1 1 10000000')
SystemLib.ogHelp('ogSetPartitionSize', 'ogSetPartitionSize int_ndisk int_npartition int_size', 'ogSetPartitionSize 1 1 10000000')
return
# Error si no se reciben 3 parámetros.
if len(args) != 3:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obtener el tamaño de la partición.
@ -1199,12 +1198,12 @@ def ogSetPartitionType(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogSetPartitionType', 'ogSetPartitionType int_ndisk int_npartition str_type', 'ogSetPartitionType 1 1 NTFS')
SystemLib.ogHelp('ogSetPartitionType', 'ogSetPartitionType int_ndisk int_npartition str_type', 'ogSetPartitionType 1 1 NTFS')
return
# Error si no se reciben 3 parámetros.
if len(args) != 3:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Sustituye nº de disco por su dispositivo.
@ -1222,7 +1221,7 @@ def ogSetPartitionType(*args):
TYPE = args[2]
ID = ogTypeToId(TYPE, PTTYPE)
if ID is None:
ogRaiseError(OG_ERR_FORMAT, f"{TYPE},{PTTYPE}")
SystemLib.ogRaiseError(OG_ERR_FORMAT, f"{TYPE},{PTTYPE}")
return
ogSetPartitionId(args[0], args[1], ID)
@ -1348,12 +1347,12 @@ def ogUnhidePartition(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogUnhidePartition', 'ogUnhidePartition int_ndisk int_npartition', 'ogUnhidePartition 1 1')
SystemLib.ogHelp('ogUnhidePartition', 'ogUnhidePartition int_ndisk int_npartition', 'ogUnhidePartition 1 1')
return
# Error si no se reciben 2 parámetros.
if len(args) != 2:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
PART = ogDiskToDev(args[0], args[1])
@ -1373,7 +1372,7 @@ def ogUnhidePartition(*args):
elif TYPE == "WIN-RESERV":
NEWTYPE = "WINDOWS"
else:
ogRaiseError(OG_ERR_PARTITION, TYPE)
SystemLib.ogRaiseError(OG_ERR_PARTITION, TYPE)
return
# Cambiar tipo de partición.
@ -1387,12 +1386,12 @@ def ogUnlockDisk(*args):
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
ogHelp('ogUnlockDisk', 'ogUnlockDisk int_ndisk', 'ogUnlockDisk 1')
SystemLib.ogHelp('ogUnlockDisk', 'ogUnlockDisk int_ndisk', 'ogUnlockDisk 1')
return
# Error si no se recibe 1 parámetro.
if len(args) != 1:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Obtener partición.

View File

@ -1,8 +1,9 @@
import subprocess
import os
import shutil
print (">>>>>>>>>>>>>>>>>>>> Load ", __name__, " <<<<<<<<<<<<<<<<<<<<<<")
import SystemLib
import CacheLib
import FileSystemLib
def ogCalculateChecksum(*args):
# Check if help is requested
@ -14,7 +15,7 @@ def ogCalculateChecksum(*args):
# Get the file path
file_path = ogGetPath(*args)
if not file_path:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
# Calculate the checksum
@ -27,7 +28,7 @@ def ogCompareChecksumFiles(*args):
# Variables locales.
ARGS = args
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "if $FUNCNAME REPO ubuntu.img CACHE ubuntu.img; then ...; fi")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "if $FUNCNAME REPO ubuntu.img CACHE ubuntu.img; then ...; fi")
return
ARGS = args
@ -60,13 +61,13 @@ def ogCalculateFullChecksum(*args):
# Variables locales.
FILE = None
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME REPO ubuntu.img ==> ef899299caf8b517ce36f1157a93d8bf")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME REPO ubuntu.img ==> ef899299caf8b517ce36f1157a93d8bf")
return
# Comprobar que existe el fichero y devolver sus datos.
FILE = ogGetPath(*args)
if not FILE:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
# Calculate the checksum
@ -79,7 +80,7 @@ def ogCopyFile(*args):
# Variables locales.
ARGS = args
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target", "$FUNCNAME REPO newfile.txt 1 2 /tmp/newfile.txt")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target", "$FUNCNAME REPO newfile.txt 1 2 /tmp/newfile.txt")
return
ARGS = args
@ -100,10 +101,10 @@ def ogCopyFile(*args):
# Comprobar fichero origen y directorio destino.
if not SOURCE:
ogRaiseError(OG_ERR_NOTFOUND, *args[:-1])
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args[:-1])
return
if not TARGET:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
# Copiar fichero (para evitar problemas de comunicaciones las copias se hacen con rsync en vez de cp).
@ -114,36 +115,36 @@ def ogDeleteFile(*args):
# Variables locales.
FILE = None
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_file", "$FUNCNAME 1 2 /tmp/newfile.txt")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_file", "$FUNCNAME 1 2 /tmp/newfile.txt")
return
# Comprobar que existe el fichero y borrarlo.
FILE = ogGetPath(*args)
if not FILE:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
try:
os.remove(FILE)
except OSError as e:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
def ogDeleteTree(*args):
# Variables locales.
DIR = None
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir")
return
# Comprobar que existe el directorio y borrarlo con su contenido.
DIR = ogGetPath(*args)
if not DIR:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
try:
shutil.rmtree(DIR)
except OSError as e:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
def ogGetPath(*args):
@ -156,7 +157,7 @@ def ogGetPath(*args):
# Si se solicita, mostrar ayuda.
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS/System32", "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc/fstab", "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS/System32")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS/System32", "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc/fstab", "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS/System32")
return
# Procesar camino según el número de parámetros.
@ -166,25 +167,25 @@ def ogGetPath(*args):
if args[0].upper() == "REPO":
FILE = os.path.join(OGIMG, args[1])
elif args[0].upper() == "CACHE":
MNTDIR = ogMountCache()
MNTDIR = CacheLib.ogMountCache()
if not MNTDIR:
return
FILE = os.path.join(MNTDIR, OGIMG, args[1])
elif args[0].upper() == "CDROM":
MNTDIR = ogMountCdrom()
MNTDIR = FileSystemLib.ogMountCdrom()
if not MNTDIR:
return
FILE = os.path.join(MNTDIR, args[1])
else:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
elif len(args) == 3:
MNTDIR = ogMount(args[0], args[1])
MNTDIR = FileSystemLib.ogMount(args[0], args[1])
if not MNTDIR:
return
FILE = os.path.join(MNTDIR, args[2])
else:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Eliminar caracteres \c / duplicados y finales.
@ -210,7 +211,7 @@ def ogGetParentPath(*args):
# Variables locales.
PARENT = None
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS", "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc", "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS")
FileSystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME \"/mnt/sda1/windows/system32\" ==> /mnt/sda1/WINDOWS", "$FUNCNAME REPO /etc/fstab ==> /opt/opengnsys/images/etc", "$FUNCNAME 1 1 \"/windows/system32\" ==> /mnt/sda1/WINDOWS")
return
# Procesar camino según el número de parámetros.
@ -221,7 +222,7 @@ def ogGetParentPath(*args):
elif len(args) == 3:
PARENT = f"{args[0]} {args[1]} {os.path.dirname(f'/{args[2]}')}"
else:
ogRaiseError(OG_ERR_FORMAT)
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
return ogGetPath(PARENT)
@ -230,7 +231,7 @@ def ogIsNewerFile(*args):
# Variables locales.
ARGS = args
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target", "if $FUNCNAME REPO ubuntu.img CACHE ubuntu.img; then ... fi")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_source [ str_repo | int_ndisk int_npartition ] path_target", "if $FUNCNAME REPO ubuntu.img CACHE ubuntu.img; then ... fi")
return
ARGS = args
@ -251,10 +252,10 @@ def ogIsNewerFile(*args):
# Comprobar que existen los ficheros origen y destino.
if not SOURCE:
ogRaiseError(OG_ERR_NOTFOUND, *args[:-1])
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args[:-1])
return
if not TARGET:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
# Devolver si el primer fichero se ha modificado después que el segundo.
@ -264,13 +265,13 @@ def ogMakeChecksumFile(*args):
# Variables locales.
FILE = None
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME REPO ubuntu.img")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_filepath", "$FUNCNAME REPO ubuntu.img")
return
# Comprobar que existe el fichero y guardar su checksum.
FILE = ogGetPath(*args)
if not FILE:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
checksum = ogCalculateChecksum(FILE)
with open(f"{FILE}.sum", "w") as f:
@ -281,13 +282,13 @@ def ogMakeDir(*args):
PARENT = None
DIR = None
if "help" in args:
ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir")
SystemLib.ogHelp("$FUNCNAME", "$FUNCNAME [ str_repo | int_ndisk int_npartition ] path_dir", "$FUNCNAME 1 2 /tmp/newdir")
return
PARENT = ogGetParentPath(*args)
if not PARENT:
ogRaiseError(OG_ERR_NOTFOUND, *args)
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, *args)
return
DIR = os.path.basename(args[-1])
os.makedirs(os.path.join(PARENT, DIR), exist_ok=True)
os.makedirs(os.path.join(PARENT, DIR), exist_ok=True)

View File

View File

@ -2,8 +2,8 @@ import subprocess
import sys
import os
from FileLib import *
from SystemLib import *
import NetLib
import SystemLib
def ogChangeRepo():
SRCIMG = ""
@ -31,7 +31,7 @@ def ogChangeRepo():
RW = ",rw" if subprocess.returncode == 0 else ",ro"
# Si REPO tomamos el repositorio y la unidad organizativa actual
REPO = ogGetRepoIp()
REPO = ogRepoIp()
OGUNIT = subprocess.run(["df", "|", "awk", "-F", " ", "'/ogimages/ {sub(\"//.*/ogimages\",\"\",$1); sub(\"/\",\"\",$1); print $1}'"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL).stdout.decode().strip()
# Parametros de entrada. Si $1 = "REPO" dejo el repositorio actual
@ -53,13 +53,13 @@ def ogChangeRepo():
subprocess.run(["eval", "$(grep \"OPTIONS=\" /scripts/ogfunctions)"])
ogEcho("session", "log", MSG_HELP_ogChangeRepo + " " + NEWREPO + " " + sys.argv[2].rstrip())
SystemLib.ogEcho("session", "log", MSG_HELP_ogChangeRepo + " " + NEWREPO + " " + sys.argv[2].rstrip())
ogConnect(NEWREPO, ogprotocol, SRCIMG, OGIMG, RW)
# Si da error volvemos a montar el inicial
if subprocess.returncode != 0:
ogConnect(REPO, ogprotocol, SRCIMG, OGIMG, RW)
ogRaiseError("session", OG_ERR_REPO, NEWREPO)
SystemLib.ogRaiseError("session", OG_ERR_REPO, NEWREPO)
return subprocess.returncode
def ogGetGroupDir():
@ -68,7 +68,7 @@ def ogGetGroupDir():
GROUP = ""
if len(sys.argv) < 2:
ogHelp("ogGetGroupDir", "ogGetGroupDir str_repo", "ogGetGroupDir REPO ==> /opt/opengnsys/images/groups/Grupo1")
SystemLib.ogHelp("ogGetGroupDir", "ogGetGroupDir str_repo", "ogGetGroupDir REPO ==> /opt/opengnsys/images/groups/Grupo1")
return
if len(sys.argv) == 1:
@ -78,7 +78,7 @@ def ogGetGroupDir():
GROUP = ogGetGroupName()
if GROUP:
DIR = ogGetPath(REPO, "/groups/" + GROUP, stderr=subprocess.DEVNULL)
DIR = FileLib.ogGetPath(REPO, "/groups/" + GROUP, stderr=subprocess.DEVNULL)
if os.path.isdir(DIR):
print(DIR)
@ -86,7 +86,7 @@ def ogGetGroupDir():
def ogGetGroupName():
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetGroupName", "ogGetGroupName", "ogGetGroupName => Grupo1")
SystemLib.ogHelp("ogGetGroupName", "ogGetGroupName", "ogGetGroupName => Grupo1")
return
if "group" in globals() and group:
@ -98,7 +98,7 @@ def ogGetHostname():
HOST = ""
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetHostname", "ogGetHostname", "ogGetHostname => pc1")
SystemLib.ogHelp("ogGetHostname", "ogGetHostname", "ogGetHostname => pc1")
return
# Tomar nombre de la variable HOSTNAME
@ -130,7 +130,7 @@ def ogGetIpAddress():
IP = ""
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetIpAddress", "ogGetIpAddress", "ogGetIpAddress => 192.168.0.10")
SystemLib.ogHelp("ogGetIpAddress", "ogGetIpAddress", "ogGetIpAddress => 192.168.0.10")
return
if "IPV4ADDR" in os.environ:
@ -154,7 +154,7 @@ def ogGetMacAddress():
MAC = ""
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetMacAddress", "ogGetMacAddress", "ogGetMacAddress => 00:11:22:33:44:55")
SystemLib.ogHelp("ogGetMacAddress", "ogGetMacAddress", "ogGetMacAddress => 00:11:22:33:44:55")
return
# Obtener direcciones Ethernet.
@ -173,7 +173,7 @@ def ogGetMacAddress():
def ogGetNetInterface():
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetNetInterface", "ogGetNetInterface", "ogGetNetInterface => eth0")
SystemLib.ogHelp("ogGetNetInterface", "ogGetNetInterface", "ogGetNetInterface => eth0")
return
if "DEVICE" in os.environ:
@ -181,14 +181,14 @@ def ogGetNetInterface():
return 0
def ogGetRepoIp():
def ogRepoIp():
# Variables locales.
SOURCE = ""
FSTYPE = ""
# Mostrar ayuda.
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetRepoIp", "ogGetRepoIp", "ogGetRepoIp => 192.168.0.2")
SystemLib.ogHelp("ogRepoIp", "ogRepoIp", "ogRepoIp => 192.168.0.2")
return
# Obtener direcciones IP, según el tipo de montaje.
@ -214,7 +214,7 @@ def ogGetServerIp():
# Mostrar ayuda.
if len(sys.argv) >= 2 and sys.argv[1] == "help":
ogHelp("ogGetServerIp", "ogGetServerIp", "ogGetServerIp => 192.168.0.2")
SystemLib.ogHelp("ogGetServerIp", "ogGetServerIp", "ogGetServerIp => 192.168.0.2")
return
# Obtener direcciones IP, según el tipo de montaje.
@ -239,7 +239,7 @@ def ogMakeGroupDir():
GROUP = ""
if len(sys.argv) < 2:
ogHelp("ogMakeGroupDir", "ogMakeGroupDir str_repo", "ogMakeGroupDir", "ogMakeGroupDir REPO")
SystemLib.ogHelp("ogMakeGroupDir", "ogMakeGroupDir str_repo", "ogMakeGroupDir", "ogMakeGroupDir REPO")
return
if len(sys.argv) == 1:
@ -247,7 +247,7 @@ def ogMakeGroupDir():
else:
REPO = sys.argv[1]
DIR = ogGetPath(REPO, "/groups/" + ogGetGroupName(), stderr=subprocess.DEVNULL)
DIR = FileLib.ogGetPath(REPO, "/groups/" + ogGetGroupName(), stderr=subprocess.DEVNULL)
if DIR:
subprocess.run(["mkdir", "-p", DIR], stderr=subprocess.DEVNULL)

View File

@ -2,8 +2,9 @@ import subprocess
import os
import re
#from engine.FileLib import *
#from engine.SystemLib import *
import ogGlobals
import SystemLib
import FileLib
def chntpw(*args):
chntpw_path = subprocess.check_output(['which', 'drbl-chntpw']).decode().strip()
@ -37,7 +38,7 @@ def ogAddRegistryValue(path_mountpoint, str_hive, str_key, str_valuename, str_va
elif str_valuetype.upper() == 'DWORD':
TYPE = 4
else:
ogRaiseError(OG_ERR_OUTOFLIMIT, str_valuetype)
SystemLib.ogRaiseError(OG_ERR_OUTOFLIMIT, str_valuetype)
return
# Add the registry value.
@ -72,17 +73,17 @@ def ogGetHivePath(path_mountpoint, str_hive):
FILE = None
# Camino del fichero de registro de usuario o de sistema (de menor a mayor prioridad).
FILE = ogGetPath(f"/{path_mountpoint}/Windows/System32/config/{str_hive}")
FILE = FileLib.ogGetPath(f"/{path_mountpoint}/Windows/System32/config/{str_hive}")
if not FILE:
FILE = ogGetPath(f"/{path_mountpoint}/Users/{str_hive}/NTUSER.DAT")
FILE = FileLib.ogGetPath(f"/{path_mountpoint}/Users/{str_hive}/NTUSER.DAT")
if not FILE:
FILE = ogGetPath(f"/{path_mountpoint}/winnt/system32/config/{str_hive}")
FILE = FileLib.ogGetPath(f"/{path_mountpoint}/winnt/system32/config/{str_hive}")
if not FILE:
FILE = ogGetPath(f"/{path_mountpoint}/Documents and Settings/{str_hive}/NTUSER.DAT")
FILE = FileLib.ogGetPath(f"/{path_mountpoint}/Documents and Settings/{str_hive}/NTUSER.DAT")
if FILE and os.path.isfile(FILE):
return FILE
else:
ogRaiseError(OG_ERR_NOTFOUND, f"{path_mountpoint} {str_hive}")
SystemLib.ogRaiseError(OG_ERR_NOTFOUND, f"{path_mountpoint} {str_hive}")
return None
def ogGetRegistryValue(path_mountpoint, str_hive, str_valuename):
@ -160,7 +161,7 @@ def ogSetRegistryValue(path_mountpoint, str_hive, str_valuename, str_data):
if f"BINARY.*<{str_valuename.rsplit('\\', 1)[-1]}>" in output:
# Procesar tipo binario (incluir nº de bytes y líneas de 16 parejas hexadecimales).
if not re.match(r'^([0-9A-F]{2} )*$', str_data):
ogRaiseError(OG_ERR_FORMAT, f'"{str_data}"')
SystemLib.ogRaiseError(OG_ERR_FORMAT, f'"{str_data}"')
return
n = len(str_data) + 1
with open(tmpfile, 'w') as f:

0
client/lib/engine/bin/__init__.py 100644 → 100755
View File

View File

View File

View File

View File

View File

@ -1,37 +1,42 @@
import sys
import os
import sys
import subprocess
sys.path.append('/opt/opengnsys/lib/engine/bin')
from NetLib import ogGetIpAddress
from SystemLib import ogRaiseError
from InventoryLib import ogListSoftware
REDUCED = False
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 = True
REDUCED = "yes"
sys.argv.pop(1)
if len(sys.argv) != 3:
og_raise_error("OG_ERR_FORMAT", "Usage: listSoftwareInfo [-r] disk partition")
SystemLib.ogRaiseError(ogGlobals.OG_ERR_FORMAT, f"{ogGlobals.MSG_FORMAT}: {PROG} ndisco nparticion")
sys.exit(1)
disk = sys.argv[1]
partition = sys.argv[2]
# Directorio del servidor donde se exportan los ficheros de registro.
SERVERLOGDIR = subprocess.run(
["awk", "-v", f"d={ogGlobals.OGLOG}", 'BEGIN {FS="[: ]"} {if ($4==d) dir=$2} END {print dir}'],
capture_output=True,
text=True,
check=True,
).stdout.strip()
# Directorio del servidor donde se exportan los ficheros de registro
server_log_dir = "/mnt/oglog" # Assuming OGLOG is mounted at /mnt/oglog
# Fichero de listado: soft-IP-disk-partition
soft_file = f"soft-{ogGetIpAddress()}-{disk}-{partition}"
log_path = os.path.join(server_log_dir, soft_file)
# Redirigir salida al fichero de listado
with open(log_path, "w") as log_file:
if not REDUCED:
ogListSoftware(disk, partition, log_file)
# Fichero de listado: soft-IP-ndisco-npart
SOFTFILE = f"soft-{NetLib.ogGetIpAddress()}-{sys.argv[1]}-{sys.argv[2]}"
# Redirigir salida al fichero de listado.
if REDUCED == "no":
if subprocess.run(["ogListSoftware", sys.argv[1], sys.argv[2]], stdout=open(f"{ogGlobals.OGLOG}/{SOFTFILE}", "w")).returncode != 0:
sys.exit(1)
else:
for line in og_list_software(disk, partition):
if "(KB" not in line:
log_file.write(line + "\n")
if subprocess.run(["ogListSoftware", sys.argv[1], sys.argv[2]], stdout=subprocess.PIPE).returncode == 0:
with open(f"{ogGlobals.OGLOG}/{SOFTFILE}", "w") as f:
f.write(subprocess.run(["egrep", "-v", "\(KB[0-9]{6}\)"], input=subprocess.PIPE).stdout.decode())
else:
sys.exit(1)
print(log_path)
# Salid: camino del fichero de listado en el servidor de repositorio.
print(f"{ogGlobals.OGLOG}/{SOFTFILE}")