diff --git a/CHANGELOG.md b/CHANGELOG.md index 816781a..59595cc 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.13.8] - 2025-06-03 + +### Fixed + +- Paid attention to return codes between python (True for success) and shell (0 for success) + ## [0.13.7] - 2025-06-02 ### Fixed diff --git a/ogclient/interfaceAdm/Configurar.py b/ogclient/interfaceAdm/Configurar.py index f233f8c..731a611 100755 --- a/ogclient/interfaceAdm/Configurar.py +++ b/ogclient/interfaceAdm/Configurar.py @@ -151,7 +151,7 @@ if 'CACHE' in sparam: SystemLib.ogEcho (['session', 'log'], None, f'[30] {ogGlobals.lang.MSG_HELP_ogCreateCache}') SystemLib.ogEcho (['session', 'log'], None, f' initCache {tch}') rc = SystemLib.ogExecAndLog ('command', CacheLib.initCache, tch) - if rc: + if not rc: SystemLib.ogRaiseError (['log', 'session'], ogGlobals.OG_ERR_CACHE, f'initCache failed') coproc.kill() sys.exit (1) diff --git a/ogclient/lib/python3/BootLib.py b/ogclient/lib/python3/BootLib.py index 71e2738..3fecd90 100644 --- a/ogclient/lib/python3/BootLib.py +++ b/ogclient/lib/python3/BootLib.py @@ -739,7 +739,7 @@ def ogGrubInstallMbr (disk, par, checkos='FALSE', kernelparam=''): neworder = neworder[0:1] + [grubentry] + neworder[1:] ## la ponemos en segundo lugar UEFILib.ogNvramSetOrder (neworder) - return eval + return not eval ## negate shell success code #/** @@ -834,7 +834,7 @@ def ogGrubInstallPartition (disk, par, checkos='FALSE', kernelparam=''): # Nombre OpenGnsys para cargador shutil.copy2 (f'{efisecondstage}/EFI/{efisubdir}/Boot/grubx64.efi', f'{efisecondstage}/EFI/{efisubdir}/Boot/ogloader.efi') - return eval + return not eval ## negate shell success code diff --git a/ogclient/lib/python3/CacheLib.py b/ogclient/lib/python3/CacheLib.py index 2918526..ef779c3 100644 --- a/ogclient/lib/python3/CacheLib.py +++ b/ogclient/lib/python3/CacheLib.py @@ -86,7 +86,7 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0): get_ptt = DiskLib.ogGetPartitionTableType (ndsk) if 'GPT' == get_ptt: # Si la tabla de particiones no es valida, volver a generarla. - if subprocess.run (['sgdisk', '-p', DISK], capture_output=True, text=True).returncode: + if subprocess.run (['sgdisk', '-p', DISK], capture_output=True, text=True).returncode: ## if True, then sgdisk failed subprocess.run (['gdisk', DISK], input='2\nw\nY\n', capture_output=True, text=True) # Si existe la cache se borra previamente if ogFindCache(): ogDeleteCache() @@ -96,7 +96,7 @@ def ogCreateCache (ndsk=1, part=4, sizecache=0): subprocess.run (['sgdisk', DISK, f'-n{part}:{START}:{END}', f'-c{part}:CACHE', f'-t{part}:{ID}']) elif 'MSDOS' == get_ptt: # Si la tabla de particiones no es valida, volver a generarla. - if subprocess.run (['parted', '-s', DISK, 'print']).returncode: + if subprocess.run (['parted', '-s', DISK, 'print']).returncode: ## if True, then parted failed subprocess.run (['fdisk', DISK], input='w\n', text=True) # Definir particiones y notificar al kernel. ID = DiskLib.ogTypeToId ('CACHE', 'MSDOS') @@ -139,12 +139,12 @@ def ogDeleteCache(): ptt = DiskLib.ogGetPartitionTableType (ndisk) if 'GPT' == ptt: # Si la tabla de particiones no es valida, volver a generarla. - if subprocess.run (['sgdisk', '-p', disk]).returncode: + if subprocess.run (['sgdisk', '-p', disk]).returncode: ## if True, then sgdisk failed subprocess.run (['gdisk', disk], input='2\nw\nY\n', text=True) subprocess.run (['sgdisk', disk, f'-d{npart}']) elif 'MSDOS' == ptt: # Si la tabla de particiones no es valida, volver a generarla. - if subprocess.run (['parted', '-s', disk, 'print']).returncode: + if subprocess.run (['parted', '-s', disk, 'print']).returncode: ## if True, then parted failed subprocess.run (['fdisk', disk], input='w', text=True) # Eliminar la partición de caché. subprocess.run (['fdisk', disk], input=f'd\n{npart}\nw', text=True) @@ -357,4 +357,4 @@ def ogUnmountCache(): #*/ ## def initCache (*args): p = subprocess.run ([f'{ogGlobals.OGSCRIPTS}/initCache.py'] + list(args)) - return p.returncode + return not p.returncode ## negate shell return code diff --git a/ogclient/lib/python3/FileLib.py b/ogclient/lib/python3/FileLib.py index 6bc0e05..64f031c 100644 --- a/ogclient/lib/python3/FileLib.py +++ b/ogclient/lib/python3/FileLib.py @@ -216,7 +216,7 @@ def ogCopyFile (src, dst): # 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) - return result.returncode + return not result.returncode ## negate shell result #/** diff --git a/ogclient/lib/python3/ImageLib.py b/ogclient/lib/python3/ImageLib.py index a99d9de..4c826ec 100644 --- a/ogclient/lib/python3/ImageLib.py +++ b/ogclient/lib/python3/ImageLib.py @@ -254,7 +254,7 @@ def ogCreateImage (disk, par, container, imgfile, tool='partclone', level='gzip' #trap p = subprocess.run (program, shell=True, check=True) errcode = p.returncode - if 0 == errcode: + if 0 == errcode: ## success i = ogGetImageInfo (IMGFILE) h = NetLib.ogGetHostname() with open (f'{IMGFILE}.info', 'w') as fd: @@ -518,7 +518,7 @@ def ogRestoreImage (repo, imgpath, disk, par): p = subprocess.run (program, shell=True, capture_output=True, text=True) print (p.stdout) print (p.stderr) - rc = p.returncode + rc = not p.returncode if not rc: SystemLib.ogRaiseError ([], ogGlobalsOG_ERR_IMAGE, f'{imgfile}, {disk}, {par}') except: @@ -607,7 +607,7 @@ def ogGetImageInfo (imgfile): ## original bash idiom is: $($COMPRESSOR -dc $IMGFILE 2>/dev/null | head -n 40 > $FILEHEAD) || ogRaiseError ## the purpose of which I can't fully comprehend #print (f'shelling out "{compressor} -dc {imgfile} |head -n 40 > {filehead}"') - if subprocess.run (f'{compressor} -dc {imgfile} |head -n 40 > {filehead}', shell=True).returncode: + if subprocess.run (f'{compressor} -dc {imgfile} |head -n 40 > {filehead}', shell=True).returncode: ## if True, then the compressor failed SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_IMAGE, f'Image format is not valid {imgfile}') return diff --git a/ogclient/lib/python3/ProtocolLib.py b/ogclient/lib/python3/ProtocolLib.py index 5303e46..94313b6 100644 --- a/ogclient/lib/python3/ProtocolLib.py +++ b/ogclient/lib/python3/ProtocolLib.py @@ -688,7 +688,7 @@ def ogTorrentStart (disk=None, par=None, container=None, torrentfile=None, torre SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, f'device or torrentfile {dev_err} not found') return - if subprocess.run (['ctorrent', '-x', source]).returncode: + if subprocess.run (['ctorrent', '-x', source]).returncode: ## if True, then ctorrent failed SystemLib.ogRaiseError ([], ogGlobals.OG_ERR_NOTFOUND, '') return None diff --git a/ogclient/scripts/deployImage.py b/ogclient/scripts/deployImage.py index 45ae486..a2d36be 100755 --- a/ogclient/scripts/deployImage.py +++ b/ogclient/scripts/deployImage.py @@ -153,7 +153,7 @@ def main (repo, imgname, disk, par, proto='UNICAST', protoopt=''): 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 retval: + if not 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}')