From 00da7454ec33f7f59af554afbe9895bf965d986e Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Thu, 13 Feb 2025 12:44:00 +0100 Subject: [PATCH] refs #1504 add ogListPartitions --- client/lib/engine/bin/DiskLib.py | 41 +++++++----------------- client/shared/functions/ogListPartitions | 22 +++++++++++++ 2 files changed, 34 insertions(+), 29 deletions(-) create mode 100755 client/shared/functions/ogListPartitions diff --git a/client/lib/engine/bin/DiskLib.py b/client/lib/engine/bin/DiskLib.py index 8b8978c..3afd71c 100755 --- a/client/lib/engine/bin/DiskLib.py +++ b/client/lib/engine/bin/DiskLib.py @@ -795,7 +795,7 @@ def ogGetPartitionId (disk, par): start_index = next (i for i, line in enumerate(lines) if 'Number' in line) for l in lines[start_index:]: idx, start, end, sz, sz_units, code, *rest = l.split() - if idx == par: + if idx == str(par): fsid = code break if fsid == '8300' and f'{disk} {par}' == CacheLib.ogFindCache(): @@ -919,7 +919,6 @@ def ogGetPartitionTableType (disk): def ogGetPartitionType (disk, par): ID = ogGetPartitionId (disk, par) if ID is None: return None - print (f'got ID ({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 Las tuplas de valores están separadas por espacios. #*/ ## -def ogListPartitions(*args): - # Variables locales - DISK = None - PART = None - NPARTS = None - TYPE = None - SIZE = None +def ogListPartitions (disk): + DISK = ogDiskToDev (disk) + if not DISK: return None - # Si se solicita, mostrar ayuda. - if len(args) == 1 and args[0] == "help": - SystemLib.ogHelp('ogListPartitions', 'ogListPartitions int_ndisk', 'ogListPartitions 1 => NTFS:10000000 EXT3:5000000 LINUX-SWAP:1000000') - return + p = [] + NPARTS = ogGetPartitionsNumber (disk) + for PART in range (1, NPARTS + 1): + 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. - 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 + return ' '.join (p) #/** diff --git a/client/shared/functions/ogListPartitions b/client/shared/functions/ogListPartitions new file mode 100755 index 0000000..e507d73 --- /dev/null +++ b/client/shared/functions/ogListPartitions @@ -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)