From b2e329c295c17c3bd8463cb445edeacbb4e08a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Ares?= Date: Wed, 10 Oct 2018 14:29:35 -0300 Subject: [PATCH 1/2] Add from_local option to transfers.rsync 'from_local' option indicates if the copy should be done from remote to local, the default is from local to remote. --- patchwork/transfers.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/patchwork/transfers.py b/patchwork/transfers.py index e7292da..8855326 100644 --- a/patchwork/transfers.py +++ b/patchwork/transfers.py @@ -9,6 +9,7 @@ def rsync( c, source, target, + from_local=False, exclude=(), delete=False, strict_host_keys=True, @@ -59,7 +60,9 @@ def rsync( ``source`` will be created inside of it. So ``rsync(c, "foldername", "/home/username")`` would create a new directory ``/home/username/foldername`` (if needed) and place the files there. - + :param from_local: + Optional, indicates if the copy should be done from remote to local, + the default is from local to remote. :param exclude: Optional, may be a single string or an iterable of strings, and is used to pass one or more ``--exclude`` options to ``rsync``. @@ -126,8 +129,14 @@ def rsync( if host.count(":") > 1: # Square brackets are mandatory for IPv6 rsync address, # even if port number is not specified - cmd = "rsync {} {} [{}@{}]:{}" + cmd_remote = '[{}@{}]' + else: + cmd_remote = '{}@{}' + + if from_local: + cmd = "rsync {} " + cmd_remote + ":{} {}" + cmd = cmd.format(options, user, host, source, target) else: - cmd = "rsync {} {} {}@{}:{}" - cmd = cmd.format(options, source, user, host, target) + cmd = "rsync {} {} " + cmd_remote + ":{}" + cmd = cmd.format(options, source, user, host, target) return c.local(cmd) From 97217458eb573497e95e2f9b1860e1a6da56286c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Ares?= Date: Thu, 11 Oct 2018 08:36:18 -0300 Subject: [PATCH 2/2] Fix 'from_local' logic, it was swapped The 'from_local' option had the opposite behavior to what it is supposed to do. --- patchwork/transfers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/patchwork/transfers.py b/patchwork/transfers.py index 8855326..b70b15d 100644 --- a/patchwork/transfers.py +++ b/patchwork/transfers.py @@ -9,7 +9,7 @@ def rsync( c, source, target, - from_local=False, + from_local=True, exclude=(), delete=False, strict_host_keys=True, @@ -60,9 +60,9 @@ def rsync( ``source`` will be created inside of it. So ``rsync(c, "foldername", "/home/username")`` would create a new directory ``/home/username/foldername`` (if needed) and place the files there. - :param from_local: - Optional, indicates if the copy should be done from remote to local, - the default is from local to remote. + :param bool from_local: + Optional, indicates if the copy should be done from local to remote or + the other way around. The default is from local to remote. :param exclude: Optional, may be a single string or an iterable of strings, and is used to pass one or more ``--exclude`` options to ``rsync``. @@ -134,9 +134,9 @@ def rsync( cmd_remote = '{}@{}' if from_local: - cmd = "rsync {} " + cmd_remote + ":{} {}" - cmd = cmd.format(options, user, host, source, target) - else: cmd = "rsync {} {} " + cmd_remote + ":{}" cmd = cmd.format(options, source, user, host, target) + else: + cmd = "rsync {} " + cmd_remote + ":{} {}" + cmd = cmd.format(options, user, host, source, target) return c.local(cmd)