refs #1098 add ogGetFsType()

pull/1/head
Natalia Serrano 2024-11-05 13:58:09 +01:00
parent 9362ea1f0a
commit 9953807e79
1 changed files with 34 additions and 30 deletions

View File

@ -1,9 +1,10 @@
import subprocess
import sys
from SystemLib import *
from DiskLib import *
from CacheLib import *
import ogGlobals
import SystemLib
import DiskLib
import CacheLib
print (">>>>>>>>>>>>>>>>>>>> Load ", __name__, " <<<<<<<<<<<<<<<<<<<<<<")
@ -336,43 +337,47 @@ def ogGetFsSize(int_ndisk, int_npartition, str_unit=None):
# Devolver el tamaño (quitar decimales si son 0).
return int(SIZE) if SIZE.is_integer() else SIZE
def ogGetFsType(int_ndisk, int_nfilesys):
# Si se solicita, mostrar ayuda.
if len(sys.argv) == 3 and sys.argv[2] == "help":
ogHelp("ogGetFsType", "ogGetFsType int_ndisk int_nfilesys", "ogGetFsType 1 1")
return
#/**
# ogGetFsType int_ndisk int_nfilesys
#@brief Devuelve el mnemonico con el tipo de sistema de archivos.
#@param int_ndisk nº de orden del disco
#@param int_nfilesys nº de orden del sistema de archivos
#@return Mnemonico
#@note Mnemonico: { EXT2, EXT3, EXT4, BTRFS, REISERFS, XFS, JFS, FAT12, FAT16, FAT32, NTFS, LINUX-SWAP, LINUX-LVM, LINUX-RAID, HFS, HFSPLUS, CACHE }
#@exception OG_ERR_FORMAT Formato incorrecto.
#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
#*/ ##
def ogGetFsType(disk, part):
PART = DiskLib.ogDiskToDev(disk, part)
if not PART: return
# Error si no se reciben 2 parámetros.
if len(sys.argv) != 3:
ogRaiseError(OG_ERR_FORMAT)
return
# Obtener partición.
PART = ogDiskToDev(int_ndisk, int_nfilesys)
if not PART:
return
# Detectar tipo de sistema de archivo (independientemente del tipo de partición).
TYPE = None
if PART.startswith("/"):
result = subprocess.run(["blkid", "-o", "export", PART], capture_output=True, text=True)
TYPE = ""
for line in result.stdout.split("\n"):
out = subprocess.run(["blkid", "-o", "export", PART], capture_output=True, text=True).stdout.splitlines()
for line in out:
if line.startswith("TYPE="):
TYPE = line.split("=")[1].upper()
break
else:
subprocess.run(["zfs", "mount", PART], stderr=subprocess.DEVNULL)
result = subprocess.run(["mount"], capture_output=True, text=True)
TYPE = ""
for line in result.stdout.split("\n"):
try:
subprocess.run(["zfs", "mount", PART])
except FileNotFoundError:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTEXEC, 'zfs')
return
out = subprocess.run(["mount"], capture_output=True, text=True).stdout.splitlines()
for line in out:
if line.startswith(PART):
TYPE = line.split()[4].upper()
break
if not TYPE:
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{disk} {part}')
return
# Componer valores correctos.
if TYPE == "EXT4":
if f"{int_ndisk} {int_nfilesys}" == ogFindCache():
if ogIsFormated(int_ndisk, int_nfilesys):
if f"{disk} {part}" == CacheLib.ogFindCache():
if ogIsFormated(disk, part):
TYPE = "CACHE"
elif TYPE == "VFAT":
result = subprocess.run(["blkid", "-po", "export", PART], capture_output=True, text=True)
@ -391,8 +396,7 @@ def ogGetFsType(int_ndisk, int_nfilesys):
elif "_MEMBER" in TYPE:
TYPE = TYPE.replace("_MEMBER", "")
if TYPE:
return TYPE
return TYPE
def ogGetMountPoint(int_ndisk, int_nfilesys):
# Si se solicita, mostrar ayuda.