mirror of https://git.48k.eu/ogclient
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
parent
782f46a199
commit
1858950af1
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue