From 4e1a188e5381c300f27f00b51d5d711f5d7ea096 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Wed, 5 Mar 2025 11:58:38 +0100 Subject: [PATCH] refs #1625 add ogGrubSetTimeOut --- ogclient/functions/ogBootLoaderSetTimeOut | 25 +++++++++++++++++ ogclient/functions/ogGrubSetTimeOut | 24 ++++++++++++++++ ogclient/lib/python3/BootLib.py | 34 +++++++++++++++++++++-- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100755 ogclient/functions/ogBootLoaderSetTimeOut create mode 100755 ogclient/functions/ogGrubSetTimeOut diff --git a/ogclient/functions/ogBootLoaderSetTimeOut b/ogclient/functions/ogBootLoaderSetTimeOut new file mode 100755 index 0000000..b2782e8 --- /dev/null +++ b/ogclient/functions/ogBootLoaderSetTimeOut @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +import sys +import argparse +import ogGlobals +from SystemLib import ogHelp +from BootLib import ogBootLoaderSetTimeOut + +parser = argparse.ArgumentParser (add_help=False) +parser.add_argument ('disk') +parser.add_argument ('par') +parser.add_argument ('timeout') + +if 2 == len (sys.argv) and 'help' == sys.argv[1]: + #parser.print_help() sale en inglés aunque la locale indique otra cosa + ogHelp ('ogBootLoaderSetTimeOut', ogGlobals.lang.MSG_SEE+' ogGrubSetTimeOut', []) + sys.exit (0) + +args = parser.parse_args() +ret = ogBootLoaderSetTimeOut (args.disk, args.par, args.timeout) + +if ret is not None: + if ret == True: sys.exit (0) + elif ret == False: sys.exit (1) + else: print (ret) diff --git a/ogclient/functions/ogGrubSetTimeOut b/ogclient/functions/ogGrubSetTimeOut new file mode 100755 index 0000000..73a3629 --- /dev/null +++ b/ogclient/functions/ogGrubSetTimeOut @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import sys +import argparse +from SystemLib import ogHelp +from BootLib import ogGrubSetTimeOut + +parser = argparse.ArgumentParser (add_help=False) +parser.add_argument ('disk') +parser.add_argument ('par') +parser.add_argument ('timeout') + +if 2 == len (sys.argv) and 'help' == sys.argv[1]: + #parser.print_help() sale en inglés aunque la locale indique otra cosa + ogHelp ('ogGrubSetTimeOut', 'ogGrubSetTimeOut int_ndiskSecondStage int_partitionSecondStage int_timeout_seconds', ['ogGrubSetTimeOut 1 4 50']) + sys.exit (0) + +args = parser.parse_args() +ret = ogGrubSetTimeOut (args.disk, args.par, args.timeout) + +if ret is not None: + if ret == True: sys.exit (0) + elif ret == False: sys.exit (1) + else: print (ret) diff --git a/ogclient/lib/python3/BootLib.py b/ogclient/lib/python3/BootLib.py index 32955f1..6f0a1ca 100644 --- a/ogclient/lib/python3/BootLib.py +++ b/ogclient/lib/python3/BootLib.py @@ -997,22 +997,25 @@ def ogGrubOgliveDefaultEntry (disk, par): #@exception OG_ERR_NOTFOUND Entrada de OgLive no encontrada en burg.cfg. #*/ ## def ogBootLoaderOgliveDefaultEntry (disk, par): +# Nombre de la función que llama a esta. func = inspect.stack()[1][3] +# Error si no puede montar sistema de archivos. PART = FileSystemLib.ogMount (disk, par) if not PART: return None - +# La función debe ser llamanda desde ogGrubOgliveDefaultEntry, ogBurgOgliveDefaultEntry or ogRefindOgliveDefaultEntry. if 'ogGrubOgliveDefaultEntry' == func: cfgfile = f'{PART}/boot/grubMBR/boot/grub/grub.cfg' else: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Use ogGrubOgliveDefaultEntry') return None - print (f'nati cfgfile ({cfgfile})') +# Comprobamos que exista fichero de configuración if not os.path.exists (cfgfile): SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, cfgfile) return None +# Detectamos cual es la entrada de ogLive numentry = 0 with open (cfgfile, 'r') as fd: while True: @@ -1022,7 +1025,7 @@ def ogBootLoaderOgliveDefaultEntry (disk, par): numentry += 1 if 'OpenGnsys Live' in l: break - print (f'nati numentry ({numentry})') +# Si no existe entrada de ogLive nos salimos if not numentry: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'menuentry OpenGnsys Live in {cfgfile}') return None @@ -1103,6 +1106,8 @@ def ogBootLoaderOgliveDefaultEntry (disk, par): #@brief ver ogBootLoaderSetTimeOut #@see ogBootLoaderSetTimeOut #*/ ## +def ogGrubSetTimeOut (disk, par, timeout): + return ogBootLoaderSetTimeOut (disk, par, timeout) #/** # ogBootLoaderSetTimeOut @@ -1116,6 +1121,29 @@ def ogBootLoaderOgliveDefaultEntry (disk, par): #@exception OG_ERR_NOTFOUND Fichero de configuración no encontrado: grub.cfg burg.cfg. #@exception OG_ERR_NOTFOUND Entrada deltema no encontrada en burg.cfg. #*/ ## +def ogBootLoaderSetTimeOut (disk, par, timeout): +# Nombre de la función que llama a esta. + func = inspect.stack()[1][3] + +# Error si no puede montar sistema de archivos. + PART = FileSystemLib.ogMount (disk, par) + if not PART: return None +# La función debe ser llamanda desde ogGrubSetTimeOut, ogBurgSetTimeOut or ogRefindSetTimeOut. + if 'ogGrubSetTimeOut' == func: + bootloader = 'grub' + bootloaderdir = 'boot/grubMBR' + cfgfile = f'{PART}/boot/grubMBR/boot/grub/grub.cfg' + else: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_FORMAT, f'Use ogGrubSetTimeOut') + return None + +# Comprobamos que exista fichero de configuración + if not os.path.exists (cfgfile): + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, cfgfile) + return None + +# Asignamos el timeOut. + subprocess.run (['sed', '-i', f's/timeout=.*$/timeout={timeout}/g', cfgfile]) #/**