From 12bb91e83de68f8ba04559b92f4eae5783bfdb08 Mon Sep 17 00:00:00 2001 From: Sanhe Hu Date: Wed, 15 Jan 2020 17:43:20 -0500 Subject: [PATCH 1/3] add remote_to_local flag to transfer.rsync function --- patchwork/_version.py | 2 +- patchwork/transfers.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/patchwork/_version.py b/patchwork/_version.py index ad38827..c711f4c 100644 --- a/patchwork/_version.py +++ b/patchwork/_version.py @@ -1,2 +1,2 @@ -__version_info__ = (1, 0, 1) +__version_info__ = (1, 0, 2) __version__ = ".".join(map(str, __version_info__)) diff --git a/patchwork/transfers.py b/patchwork/transfers.py index e7292da..8f8e70c 100644 --- a/patchwork/transfers.py +++ b/patchwork/transfers.py @@ -14,6 +14,7 @@ def rsync( strict_host_keys=True, rsync_opts="", ssh_opts="", + remote_to_local=False, ): """ Convenient wrapper around your friendly local ``rsync``. @@ -77,6 +78,9 @@ def rsync( :param str ssh_opts: Like ``rsync_opts`` but specifically for the SSH options string (rsync's ``--rsh`` flag.) + :param bool remote_to_local: + boolean flag that indicate whether you want to sync from remote to local. + By default it is sync from local to remote. """ # Turn single-string exclude into a one-item list for consistency if isinstance(exclude, six.string_types): @@ -126,8 +130,14 @@ def rsync( if host.count(":") > 1: # Square brackets are mandatory for IPv6 rsync address, # even if port number is not specified - cmd = "rsync {} {} [{}@{}]:{}" + if remote_to_local: + cmd = "rsync {options} [{user}@{host}]:{target} {source}" + else: + cmd = "rsync {options} {source} [{user}@{host}]:{target}" else: - cmd = "rsync {} {} {}@{}:{}" - cmd = cmd.format(options, source, user, host, target) + if remote_to_local: + cmd = "rsync {options} {user}@{host}:{target} {source}" + else: + cmd = "rsync {options} {source} {user}@{host}:{target}" + cmd = cmd.format(options=options, source=source, user=user, host=host, target=target) return c.local(cmd) From 1d8a08c57416e1e5219190f8c85172f706291394 Mon Sep 17 00:00:00 2001 From: Sanhe Hu Date: Wed, 15 Jan 2020 17:49:25 -0500 Subject: [PATCH 2/3] fix code style to adapt flake8 --- patchwork/transfers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/patchwork/transfers.py b/patchwork/transfers.py index 8f8e70c..3ff38a6 100644 --- a/patchwork/transfers.py +++ b/patchwork/transfers.py @@ -139,5 +139,11 @@ def rsync( cmd = "rsync {options} {user}@{host}:{target} {source}" else: cmd = "rsync {options} {source} {user}@{host}:{target}" - cmd = cmd.format(options=options, source=source, user=user, host=host, target=target) + cmd = cmd.format( + options=options, + source=source, + user=user, + host=host, + target=target, + ) return c.local(cmd) From b57640acfd7816cb25927d8e96b4d8297d3f8f70 Mon Sep 17 00:00:00 2001 From: Sanhe Hu Date: Wed, 15 Jan 2020 17:56:43 -0500 Subject: [PATCH 3/3] fix code style --- patchwork/transfers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patchwork/transfers.py b/patchwork/transfers.py index 3ff38a6..bf835f0 100644 --- a/patchwork/transfers.py +++ b/patchwork/transfers.py @@ -79,8 +79,8 @@ def rsync( Like ``rsync_opts`` but specifically for the SSH options string (rsync's ``--rsh`` flag.) :param bool remote_to_local: - boolean flag that indicate whether you want to sync from remote to local. - By default it is sync from local to remote. + boolean flag that indicate whether you want to sync from + remote to local. By default it is sync from local to remote. """ # Turn single-string exclude into a one-item list for consistency if isinstance(exclude, six.string_types):