From: Claudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Date: Tue, 6 Sep 2011 18:06:40 +0000 (+0200)
Subject: Fix sudo in popen_python code
X-Git-Tag: nepi-3.0.0~245
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=437177ecbb958940254f0fa9638429e1f02be195;p=nepi.git

Fix sudo in popen_python code
---

diff --git a/src/nepi/util/server.py b/src/nepi/util/server.py
index 79067125..7a71eef7 100644
--- a/src/nepi/util/server.py
+++ b/src/nepi/util/server.py
@@ -848,8 +848,6 @@ def popen_python(python_code,
 
     shell = False
     cmd = ""
-    if sudo:
-        cmd +="sudo "
     if python_path:
         python_path.replace("'", r"'\''")
         cmd = """PYTHONPATH="$PYTHONPATH":'%s' """ % python_path
@@ -867,6 +865,12 @@ def popen_python(python_code,
         repr(os.path.dirname(os.path.dirname(nepi.__file__))).replace("'",'"'),
     )
 
+    if sudo:
+        if ';' in cmd:
+            cmd = "sudo bash -c " + shell_escape(cmd)
+        else:
+            cmd = "sudo " + cmd
+
     if communication == DC.ACCESS_SSH:
         tmp_known_hosts = None
         args = ['ssh',
@@ -887,7 +891,7 @@ def popen_python(python_code,
                 server_key, host, port, args)
         args.append(cmd)
     else:
-        args = [cmd]
+        args = cmd
         shell = True
 
     # connects to the remote host and starts a remote