From 4cc8b1be1d0e7d338d93db1df441bf06009e484b Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 28 Jan 2025 15:58:12 +0100 Subject: [PATCH] refs #1334 add ogLockImage --- client/lib/engine/bin/ImageLib.py | 16 +++++++++++++++ client/shared/functions/ogLockImage | 30 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 client/shared/functions/ogLockImage diff --git a/client/lib/engine/bin/ImageLib.py b/client/lib/engine/bin/ImageLib.py index 1a789e7..fbdeb74 100644 --- a/client/lib/engine/bin/ImageLib.py +++ b/client/lib/engine/bin/ImageLib.py @@ -358,6 +358,22 @@ def ogIsImageLocked (container=None, imgfile=None): #@note repo = { REPO, CACHE } #@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 #/** diff --git a/client/shared/functions/ogLockImage b/client/shared/functions/ogLockImage new file mode 100755 index 0000000..0c8f505 --- /dev/null +++ b/client/shared/functions/ogLockImage @@ -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)