cosmetic
[nepi.git] / nepi / util / sshfuncs.py
index 663eeb7..1b4d389 100644 (file)
@@ -410,8 +410,8 @@ def rcopy(source, dest,
     log_msg = " rcopy - host {} - command {} ".format(host, " ".join(map(str, args)))
     
     return _retry_rexec(args, log_msg, env = None, retry = retry, 
-            tmp_known_hosts = tmp_known_hosts,
-            blocking = True)
+                        tmp_known_hosts = tmp_known_hosts,
+                        blocking = True)
 
 def rspawn(command, pidfile, 
            stdout = '/dev/null', 
@@ -683,6 +683,12 @@ fi
 
     return (out, err), proc
 
+# add quotes around a shell arg only if it has spaces
+def pretty_arg(shell_arg):
+    return shell_arg if ' ' not in shell_arg else "'{}'".format(shell_arg)
+def pretty_args(shell_args):
+    return " ".join([pretty_arg(shell_arg) for shell_arg in shell_args])
+
 def _retry_rexec(args,
                  log_msg,
                  stdout = subprocess.PIPE,
@@ -695,7 +701,7 @@ def _retry_rexec(args,
 
     for x in range(retry):
         # display command actually invoked when debug is turned on
-        message = " ".join( [ "'{}'".format(arg) for arg in args ] )
+        message = pretty_args(args)
         log("sshfuncs: invoking {}".format(message), logging.DEBUG)
         extras = {} if PY2 else {'universal_newlines' : True}
         # connects to the remote host and starts a remote connection
@@ -831,7 +837,7 @@ def _communicate(proc, input, timeout=None, err_on_timeout=True):
             # we can write up to PIPE_BUF bytes without risk
             # blocking.  POSIX defines PIPE_BUF >= 512
             bytes_written = os.write(proc.stdin.fileno(),
-                    buffer(input, input_offset, 512))
+                                     buffer(input, input_offset, 512))
             input_offset += bytes_written
 
             if input_offset >= len(input):