refs #1098 add ogGetFsType()
parent
9362ea1f0a
commit
9953807e79
|
@ -1,9 +1,10 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from SystemLib import *
|
import ogGlobals
|
||||||
from DiskLib import *
|
import SystemLib
|
||||||
from CacheLib import *
|
import DiskLib
|
||||||
|
import CacheLib
|
||||||
|
|
||||||
print (">>>>>>>>>>>>>>>>>>>> Load ", __name__, " <<<<<<<<<<<<<<<<<<<<<<")
|
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).
|
# Devolver el tamaño (quitar decimales si son 0).
|
||||||
return int(SIZE) if SIZE.is_integer() else SIZE
|
return int(SIZE) if SIZE.is_integer() else SIZE
|
||||||
|
|
||||||
def ogGetFsType(int_ndisk, int_nfilesys):
|
#/**
|
||||||
# Si se solicita, mostrar ayuda.
|
# ogGetFsType int_ndisk int_nfilesys
|
||||||
if len(sys.argv) == 3 and sys.argv[2] == "help":
|
#@brief Devuelve el mnemonico con el tipo de sistema de archivos.
|
||||||
ogHelp("ogGetFsType", "ogGetFsType int_ndisk int_nfilesys", "ogGetFsType 1 1")
|
#@param int_ndisk nº de orden del disco
|
||||||
return
|
#@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.
|
TYPE = None
|
||||||
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).
|
|
||||||
if PART.startswith("/"):
|
if PART.startswith("/"):
|
||||||
result = subprocess.run(["blkid", "-o", "export", PART], capture_output=True, text=True)
|
out = subprocess.run(["blkid", "-o", "export", PART], capture_output=True, text=True).stdout.splitlines()
|
||||||
TYPE = ""
|
for line in out:
|
||||||
for line in result.stdout.split("\n"):
|
|
||||||
if line.startswith("TYPE="):
|
if line.startswith("TYPE="):
|
||||||
TYPE = line.split("=")[1].upper()
|
TYPE = line.split("=")[1].upper()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
subprocess.run(["zfs", "mount", PART], stderr=subprocess.DEVNULL)
|
try:
|
||||||
result = subprocess.run(["mount"], capture_output=True, text=True)
|
subprocess.run(["zfs", "mount", PART])
|
||||||
TYPE = ""
|
except FileNotFoundError:
|
||||||
for line in result.stdout.split("\n"):
|
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):
|
if line.startswith(PART):
|
||||||
TYPE = line.split()[4].upper()
|
TYPE = line.split()[4].upper()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if not TYPE:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'{disk} {part}')
|
||||||
|
return
|
||||||
|
|
||||||
# Componer valores correctos.
|
# Componer valores correctos.
|
||||||
if TYPE == "EXT4":
|
if TYPE == "EXT4":
|
||||||
if f"{int_ndisk} {int_nfilesys}" == ogFindCache():
|
if f"{disk} {part}" == CacheLib.ogFindCache():
|
||||||
if ogIsFormated(int_ndisk, int_nfilesys):
|
if ogIsFormated(disk, part):
|
||||||
TYPE = "CACHE"
|
TYPE = "CACHE"
|
||||||
elif TYPE == "VFAT":
|
elif TYPE == "VFAT":
|
||||||
result = subprocess.run(["blkid", "-po", "export", PART], capture_output=True, text=True)
|
result = subprocess.run(["blkid", "-po", "export", PART], capture_output=True, text=True)
|
||||||
|
@ -391,7 +396,6 @@ def ogGetFsType(int_ndisk, int_nfilesys):
|
||||||
elif "_MEMBER" in TYPE:
|
elif "_MEMBER" in TYPE:
|
||||||
TYPE = TYPE.replace("_MEMBER", "")
|
TYPE = TYPE.replace("_MEMBER", "")
|
||||||
|
|
||||||
if TYPE:
|
|
||||||
return TYPE
|
return TYPE
|
||||||
|
|
||||||
def ogGetMountPoint(int_ndisk, int_nfilesys):
|
def ogGetMountPoint(int_ndisk, int_nfilesys):
|
||||||
|
|
Loading…
Reference in New Issue