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.
more_events
Jose M. Guisado 2023-02-22 14:16:26 +01:00
parent 782f46a199
commit 1858950af1
1 changed files with 10 additions and 10 deletions

View File

@ -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):
"""