refs #1594 simplify a couple of lines

code-review
Natalia Serrano 2025-02-20 14:00:41 +01:00
parent acf2c1dc49
commit e6937a211a
1 changed files with 5 additions and 8 deletions

View File

@ -176,9 +176,7 @@ def ogCreatePartitions (disk, parts):
ogCreatePartitionTable (ND) 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) p = subprocess.run (['sfdisk', DISK], input=sfdisk_input, capture_output=True, text=True)
print (f'rc ({p.returncode}) stdout ({p.stdout}) stderr ({p.stderr})')
subprocess.run (['partprobe', DISK]) subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache() if CACHESIZE: CacheLib.ogMountCache()
return True return True
@ -257,10 +255,11 @@ def ogCreateGptPartitions (disk, parts):
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, TYPE) SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_PARTITION, TYPE)
return None 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 * SIZE SIZE *= 2
# SIZE debe ser múltiplo de ALIGN, si no gdisk lo mueve automáticamente. # SIZE debe ser múltiplo de ALIGN, si no gdisk lo mueve automáticamente.
DIV = SIZE // ALIGN SIZE = (SIZE // ALIGN) * ALIGN
SIZE = DIV * ALIGN
# Generar datos para la partición.
# En el caso de que la partición sea EMPTY no se crea nada # En el caso de que la partición sea EMPTY no se crea nada
if 'EMPTY' != TYPE: if 'EMPTY' != TYPE:
OPTIONS += [f'-n{PART}:{START}:+{SIZE}', f'-t{PART}:{ID}'] OPTIONS += [f'-n{PART}:{START}:+{SIZE}', f'-t{PART}:{ID}']
@ -276,14 +275,12 @@ def ogCreateGptPartitions (disk, parts):
# 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) FileSystemLib.ogUnmountAll (ND)
if CACHESIZE: if CACHESIZE: CacheLib.ogUnmountCache()
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) ogCreatePartitionTable (ND)
# Definir particiones y notificar al kernel. # Definir particiones y notificar al kernel.
# Borramos primero las particiones y luego creamos las nuevas
subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK]) subprocess.run (['sgdisk'] + DELOPTIONS + OPTIONS + [DISK])
subprocess.run (['partprobe', DISK]) subprocess.run (['partprobe', DISK])
if CACHESIZE: CacheLib.ogMountCache() if CACHESIZE: CacheLib.ogMountCache()