parent
c6735b15ee
commit
04d0b2208b
|
@ -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
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue