diff --git a/CHANGELOG.md b/CHANGELOG.md index af851fe..3acd5f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.14.2-pre1] - 2025-06-09 + +### Fixed + +- Get rc of bash pipelines in ProtocolLib + ## [0.14.1] - 2025-06-07 ### Fixed diff --git a/ogclient/lib/python3/FileLib.py b/ogclient/lib/python3/FileLib.py index 64f031c..301c618 100644 --- a/ogclient/lib/python3/FileLib.py +++ b/ogclient/lib/python3/FileLib.py @@ -215,7 +215,7 @@ def ogCopyFile (src, dst): return # Copiar fichero (para evitar problemas de comunicaciones las copias se hacen con rsync en vez de cp). - result = subprocess.run(["rsync", "--progress", "--inplace", "-avh", SOURCE, TARGET], capture_output=True, text=True) + result = subprocess.run(["rsync", "--progress", "--inplace", "-avh", SOURCE, TARGET], text=True) ## they want the output return not result.returncode ## negate shell result diff --git a/ogclient/lib/python3/ProtocolLib.py b/ogclient/lib/python3/ProtocolLib.py index 94313b6..648255a 100644 --- a/ogclient/lib/python3/ProtocolLib.py +++ b/ogclient/lib/python3/ProtocolLib.py @@ -129,10 +129,9 @@ def ogUcastSendPartition (disk, par, sess, tool, level): cmd = ogUcastSyntax ('SENDPARTITION', sess, device=PART, tool=tool, level=level) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_UCASTSENDPARTITION, ' ') + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_UCASTSENDPARTITION, f'pipeline "{cmd}" returned code "{rc}"') return None return True @@ -161,10 +160,9 @@ def ogUcastReceiverPartition (disk, par, sess, tool, level): cmd = ogUcastSyntax ('RECEIVERPARTITION', sess, device=PART, tool=tool, level=level) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_UCASTRECEIVERPARTITION, ' ') + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_UCASTRECEIVERPARTITION, f'pipeline "{cmd}" returned code "{rc}"') return None return True @@ -226,16 +224,16 @@ def ogUcastSendFile (disk=None, par=None, container=None, file=None, sess=None): return path2 = FileLib.ogGetPath (file=source) + print (f'nati path2 ({path2})') if not path2: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found') return cmd = ogUcastSyntax ('SENDFILE', sess, file=source) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_UCASTSENDFILE, ' ') + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_UCASTSENDFILE, f'pipeline "{cmd}" returned code "{rc}"') return None return True @@ -485,16 +483,16 @@ def ogMcastSendFile (disk=None, par=None, container=None, file=None, sess=None): return path2 = FileLib.ogGetPath (file=source) + print (f'nati path2 ({path2})') if not path2: SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or file {dev_err} not found') return cmd = ogMcastSyntax ('SENDFILE', sess, file=source) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTSENDFILE, ' ') + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTSENDFILE, f'pipeline "{cmd}" returned code "{rc}"') return None return True @@ -553,10 +551,9 @@ def ogMcastReceiverFile (disk=None, par=None, container=None, file=None, sess=No cmd = ogMcastSyntax ('RECEIVERFILE', sess, file=os.path.join (targetdir, targetfile)) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTRECEIVERFILE, targetfile) + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTRECEIVERFILE, f'pipeline "{cmd}" returned code "{rc}"') return None return True @@ -586,10 +583,9 @@ def ogMcastSendPartition (disk, par, sess, tool, compressor): FileSystemLib.ogUnmount (disk, par) cmd = ogMcastSyntax ('SENDPARTITION', sess, device=PART, tool=tool, level=compressor) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTSENDPARTITION, ' ') + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTSENDPARTITION, f'pipeline "{cmd}" returned code "{rc}"') return None return True @@ -612,10 +608,9 @@ def ogMcastReceiverPartition (disk, par, sess, tool, compressor): FileSystemLib.ogUnmount (disk, par) cmd = ogMcastSyntax ('RECEIVERPARTITION', sess, device=PART, tool=tool, level=compressor) if not cmd: return None - try: - subprocess.run (cmd, shell=True, check=True) - except subprocess.CalledProcessError: - SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTRECEIVERPARTITION, ' ') ## original code has OG_ERR_MCASTSENDPARTITION + rc = subprocess.run (cmd, shell=True).returncode + if rc: + SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_MCASTRECEIVERPARTITION, f'pipeline "{cmd}" returned code "{rc}"') ## original code has OG_ERR_MCASTSENDPARTITION return None return True diff --git a/ogclient/scripts/deployImage.py b/ogclient/scripts/deployImage.py index 83ccafa..03fa1e8 100755 --- a/ogclient/scripts/deployImage.py +++ b/ogclient/scripts/deployImage.py @@ -140,16 +140,17 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): # Si existe, ejecuta script personalizado "restoreImageCustom"; si no, llama al genérico "restoreImage". if shutil.which ('restoreImageCustom'): SystemLib.ogEcho (['log', 'session'], None, f'[55] {ogGlobals.lang.MSG_HELP_ogRestoreImage}: restoreImageCustom {params}') - retval = not subprocess.run (['restoreImageCustom'] + params).returncode + retval = subprocess.run (['restoreImageCustom'] + params).returncode else: SystemLib.ogEcho (['log', 'session'], None, f'[55] {ogGlobals.lang.MSG_HELP_ogRestoreImage}: restoreImage {params}') - retval = not subprocess.run (['restoreImage.py'] + params).returncode + retval = subprocess.run (['restoreImage.py'] + params).returncode # Mostrar resultados. resumerestoreimage = subprocess.run (['grep', '--max-count', '1', 'Total Time:', ogGlobals.OGLOGCOMMAND], capture_output=True, text=True).stdout SystemLib.ogEcho (['log', 'session'], None, f' [ ] {resumerestoreimage} ') # Si la transferencia ha dado error me salgo. - if not retval: + if retval: ## subprocess.run failed + SystemLib.ogEcho (['log', 'session'], None, f'[60] {ogGlobals.lang.MSG_HELP_ogRestoreImage}: error: returncode not 0 but "{retval}"') SystemLib.ogRaiseError ('session', ogGlobals.OG_ERR_IMAGE, f'{repo} {imgname}') if SystemLib.ogGetCaller() != 'EjecutarScript': SystemLib.ogEcho (['log', 'session'], None, f'{ogGlobals.lang.MSG_INTERFACE_END} {ogGlobals.OG_ERR_IMAGE}') @@ -172,9 +173,6 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): # Registro de fin de ejecución # Si se ha llamado desde ejecutar script no lo muestro para no repetir. if SystemLib.ogGetCaller() != 'EjecutarScript': - ## turn shell's success into python success (without ending up with True or False, because we want to ogEcho() "0"/"1" rather than ogEcho() "True"/"False") - if retval: retval = 0 - else: retval = 1 SystemLib.ogEcho (['log', 'session'], None, f'{ogGlobals.lang.MSG_INTERFACE_END} {retval}') sys.exit (retval)