refs #1499 add ogLockDisk
parent
375a3a8ad0
commit
8b11b4e08d
|
@ -1093,7 +1093,7 @@ def ogIdToType(ID):
|
|||
def ogIsDiskLocked (disk):
|
||||
DISK = ogDiskToDev (disk)
|
||||
if not DISK: return False
|
||||
return os.path.isfile (f'/var/lock/lock{DISK.replace('/', '-')}')
|
||||
return os.path.isfile (f'/var/lock/lock{DISK.replace("/", "-")}')
|
||||
|
||||
|
||||
#/**
|
||||
|
@ -1203,29 +1203,10 @@ def ogListLogicalPartitions(*args):
|
|||
#@exception OG_ERR_NOTFOUND Disco o particion no corresponden con un dispositivo.
|
||||
#@note El fichero de bloqueo se localiza en \c /var/lock/disk, siendo \c disk el dispositivo del disco, sustituyendo el carácter "/" por "-".
|
||||
#*/ ##
|
||||
def ogLockDisk(*args):
|
||||
# Variables locales
|
||||
DISK = None
|
||||
LOCKFILE = None
|
||||
|
||||
# Si se solicita, mostrar ayuda.
|
||||
if len(args) == 1 and args[0] == "help":
|
||||
SystemLib.ogHelp('ogLockDisk', 'ogLockDisk int_ndisk', 'ogLockDisk 1')
|
||||
return
|
||||
|
||||
# Error si no se recibe 1 parámetro.
|
||||
if len(args) != 1:
|
||||
SystemLib.ogRaiseError(OG_ERR_FORMAT)
|
||||
return
|
||||
|
||||
# Obtener partición.
|
||||
DISK = ogDiskToDev(args[0])
|
||||
if DISK is None:
|
||||
return
|
||||
|
||||
# Crear archivo de bloqueo exclusivo.
|
||||
LOCKFILE = f"/var/lock/lock{DISK.replace('/', '-')}"
|
||||
open(LOCKFILE, 'a').close()
|
||||
def ogLockDisk (disk):
|
||||
DISK = ogDiskToDev (disk)
|
||||
if not DISK: return None
|
||||
open (f'/var/lock/lock{DISK.replace("/", "-")}', 'a').close()
|
||||
|
||||
|
||||
#/**
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from SystemLib import ogHelp
|
||||
from DiskLib import ogLockDisk
|
||||
|
||||
parser = argparse.ArgumentParser (add_help=False)
|
||||
parser.add_argument ('disk')
|
||||
|
||||
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||
ogHelp ('ogLockDisk', 'ogLockDisk int_ndisk', ['ogLockDisk 1'])
|
||||
sys.exit (0)
|
||||
|
||||
args = parser.parse_args()
|
||||
ret = ogLockDisk (args.disk)
|
||||
|
||||
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