From acf2c1dc4901581007d8f6773830eec543c6da37 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 20 Feb 2025 13:57:57 +0100 Subject: [PATCH] refs #1594 indent some comments --- client/lib/engine/bin/DiskLib.py | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/client/lib/engine/bin/DiskLib.py b/client/lib/engine/bin/DiskLib.py index e6bd26d..88e12da 100755 --- a/client/lib/engine/bin/DiskLib.py +++ b/client/lib/engine/bin/DiskLib.py @@ -70,7 +70,7 @@ def ogCreatePartitions (disk, parts): SECTORS = ogGetLastSector (disk) -# Se recalcula el nº de sectores del disco 1, si existe partición de caché. + # Se recalcula el nº de sectores del disco si existe partición de caché. CACHESIZE = 0 CACHEPART = CacheLib.ogFindCache() if CACHEPART: @@ -78,7 +78,7 @@ def ogCreatePartitions (disk, parts): if ND == cache_disk: CACHESIZE = int (CacheLib.ogGetCacheSize()) * 2 -# Sector de inicio (la partición 1 empieza en el sector 63). + # Sector de inicio (la partición 1 empieza en el sector 63). IODISCO = ogDiskToDev (disk) IOSIZE = 0 fdisk_out = subprocess.run (['fdisk', '-l', IODISCO], capture_output=True, text=True).stdout @@ -101,19 +101,19 @@ def ogCreatePartitions (disk, parts): PART = 1 -# Fichero temporal de entrada para "sfdisk" + # Fichero temporal de entrada para "sfdisk" sfdisk_input = 'unit: sectors\n\n' NVME_PREFIX = 'p' if 'nvme' in DISK else '' -# Generar fichero de entrada para "sfdisk" con las particiones. + # Generar fichero de entrada para "sfdisk" con las particiones. for p in parts: - # Conservar los datos de la partición de caché. + # Conservar los datos de la partición de caché. if f'{ND} {PART}' == CACHEPART and CACHESIZE: sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, Id=ca\n' PART += 1 - # Leer formato de cada parámetro - Tipo:Tamaño + # Leer formato de cada parámetro - Tipo:Tamaño TYPE, SIZE = p.split (':') try: SIZE = int (SIZE) @@ -121,23 +121,23 @@ def ogCreatePartitions (disk, parts): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, SIZE) return None - # Obtener identificador de tipo de partición válido. + # Obtener identificador de tipo de partición válido. ID = ogTypeToId (TYPE, 'MSDOS') if 'CACHE' == TYPE or not ID: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, TYPE) return None - # Comprobar tamaño numérico y convertir en sectores de 512 B. + # Comprobar tamaño numérico y convertir en sectores de 512 B. SIZE *= 2 - # Comprobar si la partición es extendida. + # Comprobar si la partición es extendida. EXTSTART = EXTSIZE = 0 if 5 == ID: if PART > 4: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, '') return None - # El inicio de la primera partición logica es el de la extendida más 4x512 + # El inicio de la primera partición logica es el de la extendida más 4x512 EXTSTART = START+2048 EXTSIZE = SIZE-2048 - # Incluir particiones lógicas dentro de la partición extendida. + # Incluir particiones lógicas dentro de la partición extendida. if 5 == PART: if not EXTSTART: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, '') @@ -148,6 +148,8 @@ def ogCreatePartitions (disk, parts): sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={START}, size={SIZE}, Id={ID}\n' # Error si se supera el nº total de sectores. START += SIZE + + # Error si se supera el nº total de sectores. if '4096' == IOSIZE and PART > 4: START += 2048 if START > SECTORS: @@ -155,24 +157,25 @@ def ogCreatePartitions (disk, parts): return None PART += 1 -# Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché. + # Si no se indican las 4 particiones primarias, definirlas como vacías, conservando la partición de caché. while PART <= 4: if f'{ND} {PART}' == CACHEPART and CACHESIZE: sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start={SECTORS+1}, size={CACHESIZE}, Id=ca\n' else: sfdisk_input += f'{DISK}{NVME_PREFIX}{PART} : start=0, size=0, Id=0\n' PART += 1 -# Si se define partición extendida sin lógicas, crear particion 5 vacía. + # Si se define partición extendida sin lógicas, crear particion 5 vacía. if 5 == PART and EXTSTART: sfdisk_input += f'{DISK}5 : start={EXTSTART}, SIZE={EXTSIZE}, Id=0\n' -# Desmontar los sistemas de archivos del disco antes de realizar las operaciones. + # Desmontar los sistemas de archivos del disco antes de realizar las operaciones. FileSystemLib.ogUnmountAll (ND) if CACHESIZE: CacheLib.ogUnmountCache() -# Si la tabla de particiones no es valida, volver a generarla. + # Si la tabla de particiones no es valida, volver a generarla. ogCreatePartitionTable (ND) -# Definir particiones y notificar al kernel. + + # Definir particiones y notificar al kernel. print (f'about to run sfdisk: ({sfdisk_input})') p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True) print (f'rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})') @@ -198,7 +201,6 @@ def ogCreatePartitions (disk, parts): #@todo Definir atributos (arranque, oculta) y tamaños en MB, GB, etc. #*/ ## def ogCreateGptPartitions (disk, parts): - # Nº total de sectores, para evitar desbordamiento (evitar redondeo). ND = disk DISK = ogDiskToDev (ND) if not DISK: return None @@ -225,7 +227,7 @@ def ogCreateGptPartitions (disk, parts): DELOPTIONS = [] OPTIONS = [] for p in parts: - # Si PART es la cache, nos la saltamos y seguimos con el siguiente numero para conservar los datos de la partición de caché. + # Conservar los datos de la partición de caché. if f'{ND} {PART}' == CACHEPART and CACHESIZE: PART += 1 @@ -284,9 +286,7 @@ def ogCreateGptPartitions (disk, parts): # Borramos primero las particiones y luego creamos las nuevas subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK]) subprocess.run (['partprobe', DISK]) - if CACHESIZE: CacheLib.ogMountCache() - return True