summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-02-22 14:16:26 +0100
committerJose M. Guisado <jguisado@soleta.eu>2023-03-02 09:09:39 +0100
commit1858950af194ef73d3ee589ae7104f7d3def9f38 (patch)
tree1525aeba16024f50b36d28c1c854dd01adfb9a3d /src
parent782f46a1991ba6661c6b1e99a7fc4ca850a1e32e (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/utils/legacy.py20
1 files changed, 10 insertions, 10 deletions
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):
"""