refs #1503 add ogGetPartitionType

code-review
Natalia Serrano 2025-02-13 12:20:09 +01:00
parent 1fdbdd637c
commit 5cc3176d74
2 changed files with 29 additions and 22 deletions

View File

@ -916,28 +916,12 @@ def ogGetPartitionTableType (disk):
#@exception OG_ERR_FORMAT Formato incorrecto.
#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
#*/ ##
def ogGetPartitionType(*args):
# Variables locales
ID = None
TYPE = None
def ogGetPartitionType (disk, par):
ID = ogGetPartitionId (disk, par)
if ID is None: return None
print (f'got ID ({ID})')
# Si se solicita, mostrar ayuda.
if len(args) == 1 and args[0] == "help":
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:
SystemLib.ogRaiseError(OG_ERR_FORMAT)
return
# Detectar id. de tipo de partición y codificar al mnemónico.
ID = ogGetPartitionId(args[0], args[1])
if ID is None:
return
TYPE = ogIdToType(ID)
print(TYPE)
return
return ogIdToType (ID)
#/**
@ -1001,7 +985,7 @@ def ogHidePartition(*args):
#*/ ##
def ogIdToType (ID):
# Obtener valor hexadecimal de 4 caracteres rellenado con 0 por delante.
ID = ID.zfill(4)
ID = ID.zfill(4).lower()
id2type = {
'0000': 'EMPTY',

View File

@ -0,0 +1,23 @@
#!/usr/bin/python3
import sys
import argparse
from SystemLib import ogHelp
from DiskLib import ogGetPartitionType
parser = argparse.ArgumentParser (add_help=False)
parser.add_argument ('disk')
parser.add_argument ('par')
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
#parser.print_help() sale en inglés aunque la locale indique otra cosa
ogHelp ('ogGetPartitionType', 'ogGetPartitionType int_ndisk int_nfilesys', ['ogGetPartitionType 1 1'])
sys.exit (0)
args = parser.parse_args()
ret = ogGetPartitionType (args.disk, args.par)
if ret is not None:
if ret == True: sys.exit (0)
elif ret == False: sys.exit (1)
else: print (ret)