From 1858950af194ef73d3ee589ae7104f7d3def9f38 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 22 Feb 2023 14:16:26 +0100 Subject: legacy: improve readability of cambiar_accesso Expand function docstring and do not use CalledProcessError handling to return True or False. Just checking for returncode value is simpler. --- src/utils/legacy.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/utils/legacy.py b/src/utils/legacy.py index aca8abe..96b32eb 100644 --- a/src/utils/legacy.py +++ b/src/utils/legacy.py @@ -5,7 +5,7 @@ import subprocess import shlex import shutil -from subprocess import PIPE +from subprocess import PIPE, DEVNULL def ogGetImageInfo(path): """ @@ -29,20 +29,20 @@ def ogGetImageInfo(path): def cambiar_acceso(mode='rw', user='opengnsys', pwd='og'): """ - 'CambiarAcceso' wrapper (admin/Interface/CambiarAcceso) + 'CambiarAcceso' (admin/Interface/CambiarAcceso) rewrite into native Python. + + Remount the (remote) samba directory that contains the OpenGnsys images. + Specify access mode ('rw', or 'ro') with mode parameter (default 'rw'). + Specify samba credentials with user and pwd parameter. + + Return True if exit-code was 0. Return False otherwise. """ if mode not in ['rw', 'ro']: raise ValueError('Invalid remount mode option') cmd = shlex.split(f'mount -o remount,{mode},username={user},password={pwd} /opt/opengnsys/images') - ret = True - try: - subprocess.run(cmd, check=True) - except CalledProcessError: - ret = False - finally: - return ret - + p = subprocess.run(cmd, stdout=DEVNULL, stderr=DEVNULL) + return p.returncode == 0 def ogChangeRepo(ip): """ -- cgit v1.2.3-18-g5258