refs #1504 add ogListPartitions
parent
5cc3176d74
commit
00da7454ec
|
@ -795,7 +795,7 @@ def ogGetPartitionId (disk, par):
|
||||||
start_index = next (i for i, line in enumerate(lines) if 'Number' in line)
|
start_index = next (i for i, line in enumerate(lines) if 'Number' in line)
|
||||||
for l in lines[start_index:]:
|
for l in lines[start_index:]:
|
||||||
idx, start, end, sz, sz_units, code, *rest = l.split()
|
idx, start, end, sz, sz_units, code, *rest = l.split()
|
||||||
if idx == par:
|
if idx == str(par):
|
||||||
fsid = code
|
fsid = code
|
||||||
break
|
break
|
||||||
if fsid == '8300' and f'{disk} {par}' == CacheLib.ogFindCache():
|
if fsid == '8300' and f'{disk} {par}' == CacheLib.ogFindCache():
|
||||||
|
@ -919,7 +919,6 @@ def ogGetPartitionTableType (disk):
|
||||||
def ogGetPartitionType (disk, par):
|
def ogGetPartitionType (disk, par):
|
||||||
ID = ogGetPartitionId (disk, par)
|
ID = ogGetPartitionId (disk, par)
|
||||||
if ID is None: return None
|
if ID is None: return None
|
||||||
print (f'got ID ({ID})')
|
|
||||||
|
|
||||||
return ogIdToType (ID)
|
return ogIdToType (ID)
|
||||||
|
|
||||||
|
@ -1076,35 +1075,19 @@ def ogIsDiskLocked (disk):
|
||||||
#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
|
#@attention El nº de partición se indica por el orden de los párametros \c parttype:partsize
|
||||||
#@attention Las tuplas de valores están separadas por espacios.
|
#@attention Las tuplas de valores están separadas por espacios.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
def ogListPartitions(*args):
|
def ogListPartitions (disk):
|
||||||
# Variables locales
|
DISK = ogDiskToDev (disk)
|
||||||
DISK = None
|
if not DISK: return None
|
||||||
PART = None
|
|
||||||
NPARTS = None
|
|
||||||
TYPE = None
|
|
||||||
SIZE = None
|
|
||||||
|
|
||||||
# Si se solicita, mostrar ayuda.
|
p = []
|
||||||
if len(args) == 1 and args[0] == "help":
|
NPARTS = ogGetPartitionsNumber (disk)
|
||||||
SystemLib.ogHelp('ogListPartitions', 'ogListPartitions int_ndisk', 'ogListPartitions 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000')
|
for PART in range (1, NPARTS + 1):
|
||||||
return
|
t = ogGetPartitionType (disk, PART)
|
||||||
|
TYPE = ogGetPartitionType (disk, PART) or 'EMPTY'
|
||||||
|
SIZE = ogGetPartitionSize (disk, PART) or 0
|
||||||
|
p.append (f'{TYPE}:{SIZE}')
|
||||||
|
|
||||||
# Error si no se recibe 1 parámetro.
|
return ' '.join (p)
|
||||||
if len(args) != 1:
|
|
||||||
SystemLib.ogRaiseError(OG_ERR_FORMAT)
|
|
||||||
return
|
|
||||||
|
|
||||||
# Procesar la salida de parted.
|
|
||||||
DISK = ogDiskToDev(args[0])
|
|
||||||
if DISK is None:
|
|
||||||
return
|
|
||||||
NPARTS = ogGetPartitionsNumber(args[0])
|
|
||||||
for PART in range(1, NPARTS + 1):
|
|
||||||
TYPE = ogGetPartitionType(args[0], PART) or "EMPTY"
|
|
||||||
SIZE = ogGetPartitionSize(args[0], PART) or 0
|
|
||||||
print(f"{TYPE}:{SIZE} ", end="")
|
|
||||||
print()
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from DiskLib import ogListPartitions
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogListPartitions', 'ogListPartitions int_ndisk', ['ogListPartitions 1'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
ret = ogListPartitions (args.disk)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
Loading…
Reference in New Issue