From 04d0b2208bd6a232694b8af3df4466f4b294b40f Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Mon, 3 Feb 2025 13:53:30 +0100 Subject: [PATCH] refs #1431 #1430 add ogIsRepoLocked, remove the unused ogCheckProgram --- client/lib/engine/bin/SystemLib.py | 58 +++++++++++--------------- client/shared/functions/ogIsRepoLocked | 17 ++++++++ 2 files changed, 41 insertions(+), 34 deletions(-) create mode 100755 client/shared/functions/ogIsRepoLocked diff --git a/client/lib/engine/bin/SystemLib.py b/client/lib/engine/bin/SystemLib.py index 9524949..338a5e3 100755 --- a/client/lib/engine/bin/SystemLib.py +++ b/client/lib/engine/bin/SystemLib.py @@ -5,6 +5,7 @@ import sys import os import shutil import inspect +import glob ## for ogExecAndLog from io import StringIO @@ -258,43 +259,32 @@ def ogRaiseError (logtypes, code, msg): #@return Código de salida: 0 - bloqueado, 1 - sin bloquear o error. #*/ def ogIsRepoLocked(): - # Variables locales - FILES = "" - FUNCNAME = ogIsRepoLocked.__name__ - - # Si se solicita, mostrar ayuda. - if len(sys.argv) > 1 and sys.argv[1] == "help": - ogHelp(f"{FUNCNAME}", f"{FUNCNAME}", f"if {FUNCNAME}(): ...") - - # No hacer nada, si no está definido el punto de montaje del repositorio. +# No hacer nada, si no está definido el punto de montaje del repositorio. if not ogGlobals.OGIMG: - return 1 + return False - # Comprobar si alguno de los ficheros abiertos por los procesos activos está en el - # punto de montaje del repositorio de imágenes. - FILES = subprocess.check_output(["find", "/proc", "-maxdepth", "2", "-type", "f", "-lname", f"{ogGlobals.OGIMG}/*"]).decode("utf-8") - return bool(FILES) +# Comprobar si alguno de los ficheros abiertos por los procesos activos está en el +# punto de montaje del repositorio de imágenes. + proc_entries = glob.glob ('/proc/[0-9]*/fd/*') + for e in proc_entries: + p = os.path.realpath (e) + if ogGlobals.OGIMG in p: + return True + return False -def ogCheckProgram(program): - FUNCNAME = ogCheckProgram.__name__ - - if not program or not isinstance(program, str): - SystemLib.ogRaiseError( - "session", - ogGlobals.OG_ERR_FORMAT, - f"Error: {ogGlobals.lang.MSG_ERR_FORMAT} {FUNCNAME} \"program\"" - ) - return - - if not shutil.which(program): - SystemLib.ogRaiseError( - "session", - ogGlobals.OG_ERR_NOTEXEC, - f"Error: The program '{program}' is not available on the system." - ) - return - - return 0 +## has no users +#def ogCheckProgram(program): +# FUNCNAME = ogCheckProgram.__name__ +# +# if not program or not isinstance(program, str): +# SystemLib.ogRaiseError ("session", ogGlobals.OG_ERR_FORMAT, f"Error: {ogGlobals.lang.MSG_ERR_FORMAT} {FUNCNAME} \"program\"") +# return +# +# if not shutil.which(program): +# SystemLib.ogRaiseError ( "session", ogGlobals.OG_ERR_NOTEXEC, f"Error: The program '{program}' is not available on the system.") +# return +# +# return 0 def ogIsVirtualMachine(): output = subprocess.run (["dmidecode", "-s", "system-product-name"], capture_output=True, text=True).stdout diff --git a/client/shared/functions/ogIsRepoLocked b/client/shared/functions/ogIsRepoLocked new file mode 100755 index 0000000..aad48d2 --- /dev/null +++ b/client/shared/functions/ogIsRepoLocked @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import sys +from SystemLib import ogHelp +from SystemLib import ogIsRepoLocked + +if 2 == len (sys.argv) and 'help' == sys.argv[1]: + #parser.print_help() sale en inglés aunque la locale indique otra cosa + ogHelp ('ogIsRepoLocked', 'ogIsRepoLocked', ['ogIsRepoLocked']) + sys.exit (0) + +ret = ogIsRepoLocked() + +if ret is not None: + if ret == True: sys.exit (0) + elif ret == False: sys.exit (1) + else: print (ret)