Andrew Macgregor avatar Andrew Macgregor committed b57543d Merge

Merged in heyvaerm/parcel/rsync-with-ssh-port (pull request #2)

Add support for non-standard ssh ports (rsync)

Comments (0)

Files changed (2)

     command.append('rsync')
     command.append('-av')
 
-    if env.key_filename is not None:
+    custom_port = int(env.port) if env.port is not None and env.port != '22' else None
+    if env.key_filename is not None or custom_port is not None:
+        ssh_arguments = []
+
+        # use specified port if it is a non-standard port
+        if custom_port is not None:
+            ssh_arguments.append("-p {0.port}".format(env))
+
         # use specified identity file to connect
+        keyfiles = []
         if type(env.key_filename) in (str, unicode): 
-            ssh_command = "'ssh -l {0.user} -i \"{0.key_filename}\"'".format(env)
-        else:
+            keyfiles = [env.key_filename]
+        elif env.key_filename:
             assert type(env.key_filename) in (list, tuple), "malformed env.key_filename: %r"%(env.key_filename)
-            ssh_command = "'ssh -l {0} {1}'".format(env.user, ' '.join(
-                ['-i "{0}"'.format(keyfile) 
-                 for keyfile in env.key_filename]))
+            keyfiles = env.key_filename
+        if keyfiles:
+            ssh_arguments.append("-l {0}".format(env.user))
+            ssh_arguments += ['-i "{0}"'.format(keyfile) for keyfile in keyfiles]
+
+        ssh_command = "'ssh {0}'".format(" ".join(ssh_arguments))
         command.extend(['-e',ssh_command])
 
     command.extend("'%s'"%s for s in sources)

tests/test_tools.py

 
         # call with single fabric env.key_filename
         from fabric.state import env
-        env.key_filename = "/some/path/to/a/keyfile.pub"
-        rsync(test_file, 'test.tar.gz')
+        from fabric.api import settings
+        with settings(key_filename="/some/path/to/a/keyfile.pub"):
+            rsync(test_file, 'test.tar.gz')
         
-        # rsync command should specify ssh command
-        self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename}\"'".format(env), rsync_local.call_args[0][0])
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename}\"'".format(env), rsync_local.call_args[0][0])
 
         # call with multiple fabric env.key_filename
-        env.key_filename = ["keyfile1.pub","keyfile2.pub"]
-        rsync(test_file, 'test.tar.gz')
+        with settings(key_filename=["keyfile1.pub","keyfile2.pub"]):
+            rsync(test_file, 'test.tar.gz')
         
-        # rsync command should specify ssh command
-        self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename[0]}\" -i \"{0.key_filename[1]}\"'".format(env), rsync_local.call_args[0][0])
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -l {0.user} -i \"{0.key_filename[0]}\" -i \"{0.key_filename[1]}\"'".format(env), rsync_local.call_args[0][0])
 
+        # call with nonstandard ssh port
+        with settings(port=2222):
+            rsync(test_file, 'test.tar.gz')
+
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -p 2222'".format(env), rsync_local.call_args[0][0])
+
+        # combine keyfile and port
+        with settings(key_filename="/some/path/to/a/keyfile.pub", port=3232):
+            rsync(test_file, 'test.tar.gz')
         
+            # rsync command should specify ssh command
+            self.assertIn("rsync -av -e 'ssh -p 3232 -l {0.user} -i \"{0.key_filename}\"'".format(env), rsync_local.call_args[0][0])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.