refs #1399 remove ogCheckStringInGroup, ogCheckStringInReg

pull/1/head
Natalia Serrano 2025-01-29 12:28:25 +01:00
parent 9997e78b31
commit 30c90442b7
3 changed files with 5 additions and 29 deletions

View File

@ -1,31 +1,5 @@
import re
def ogCheckStringInGroup(element, group):
"""
Función para determinar si el elemento pertenece a un conjunto.
:param element: elemento a comprobar
:param group: grupo de elementos para comprobar tipo "valor1 valor2 valor3"
:return: True si pertenece al grupo, False si NO pertenece al grupo
"""
if not isinstance(element, str) or not isinstance(group, str):
raise ValueError("Formato incorrecto, ambos parámetros deben ser cadenas.")
return element in group.split()
def ogCheckStringInReg(element, regex):
"""
Función para determinar si el elemento contiene una "expresión regular".
:param element: elemento a comprobar
:param regex: expresión regular
:return: True si coincide con la expresión, False si NO coincide con la expresión
"""
if not isinstance(element, str) or not isinstance(regex, str):
raise ValueError("Formato incorrecto, ambos parámetros deben ser cadenas.")
return re.match(regex, element) is not None
#/**

View File

@ -236,15 +236,17 @@ def ogRaiseError (logtypes, code, msg):
MSG = ogGlobals.lang.MSG_ERR_GENERIC
CODE = ogGlobals.OG_ERR_GENERIC
# Obtener lista de funciones afectadas, incluyendo el script que las llama.
call_stack = [i[3] for i in inspect.stack()]
if len (call_stack) < 2: return ## shouldn't happen
call_stack.pop() ## remove '<module>'
call_stack.pop(0) ## remove 'ogRaiseError'
str_call_stack = ' '.join (call_stack)
# Mostrar mensaje de error si es función depurable y salir con el código indicado.
if code == ogGlobals.OG_ERR_FORMAT or \
StringLib.ogCheckStringInGroup (str_call_stack, ogGlobals.NODEBUGFUNCTIONS) or \
not (len(call_stack)>0 and StringLib.ogCheckStringInGroup (call_stack[0], ogGlobals.NODEBUGFUNCTIONS)):
(str_call_stack in ogGlobals.NODEBUGFUNCTIONS) or \
not (len(call_stack)>0 and (call_stack[0] in ogGlobals.NODEBUGFUNCTIONS)):
ogEcho (logtypes, "error", f"{str_call_stack.replace(' ', '<-')}: {MSG}")
return code

View File

@ -45,7 +45,7 @@ MCASTWAIT=30 # timeout (segundos) para abortar la la tran
#BACKUP=False # Realizar copia de seguridad antes de crear la imagen.
#IMGFS='EXT4' # Sistema de archivo de la imagenes sincronizadas. EXT4 o BTRFS
#OGSLEEP=20 # Tiempo de sleep antes de realizar el reboot
NODEBUGFUNCTIONS='ogCreateImageSyntax ogGetHivePath ogGetOsType ogRestoreImageSyntax ogUnmountAll ogUnmountCache' # Funciones que no deben mostrar salida de avisos si son llamadas por otras funciones.
NODEBUGFUNCTIONS=['ogCreateImageSyntax', 'ogGetHivePath', 'ogGetOsType', 'ogRestoreImageSyntax', 'ogUnmountAll', 'ogUnmountCache'] # Funciones que no deben mostrar salida de avisos si son llamadas por otras funciones.
#DEFAULTSPEED=''
## /engine.cfg