refs #1334 add ogLockImage
parent
ad9c498e38
commit
4cc8b1be1d
|
@ -358,6 +358,22 @@ def ogIsImageLocked (container=None, imgfile=None):
|
||||||
#@note repo = { REPO, CACHE }
|
#@note repo = { REPO, CACHE }
|
||||||
#@exception OG_ERR_FORMAT formato incorrecto.
|
#@exception OG_ERR_FORMAT formato incorrecto.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
def ogLockImage (container=None, imgfile=None):
|
||||||
|
if not imgfile:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, '')
|
||||||
|
return None
|
||||||
|
|
||||||
|
if container:
|
||||||
|
imgdir = FileLib.ogGetParentPath (src=container, file=imgfile)
|
||||||
|
else:
|
||||||
|
imgdir = FileLib.ogGetParentPath (file=imgfile)
|
||||||
|
|
||||||
|
try:
|
||||||
|
bn = os.path.basename (imgfile)
|
||||||
|
open (f'{imgdir}/{bn}.lock', 'w').close()
|
||||||
|
except:
|
||||||
|
SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTWRITE, f'{container} {imgfile}')
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
#/**
|
#/**
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from ImageLib import ogLockImage
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogLockImage', 'ogLockImage [str_repo] path_image', ['ogLockImage /opt/opengnsys/images/aula1/win7.img', 'ogLockImage REPO /aula1/win7.img'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
if 2 == len (sys.argv):
|
||||||
|
parser.add_argument ('file')
|
||||||
|
elif 3 == len (sys.argv):
|
||||||
|
parser.add_argument ('container')
|
||||||
|
parser.add_argument ('file')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if 2 == len (sys.argv):
|
||||||
|
ret = ogLockImage (imgfile=args.file)
|
||||||
|
elif 3 == len (sys.argv):
|
||||||
|
ret = ogLockImage (container=args.container, imgfile=args.file)
|
||||||
|
|
||||||
|
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