Fix sudo in popen_python code
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 6 Sep 2011 18:06:40 +0000 (20:06 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 6 Sep 2011 18:06:40 +0000 (20:06 +0200)
src/nepi/util/server.py

index 7906712..7a71eef 100644 (file)
@@ -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