Skip to content

support rsync from remote to local #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion patchwork/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (1, 0, 1)
__version_info__ = (1, 0, 2)
__version__ = ".".join(map(str, __version_info__))
22 changes: 19 additions & 3 deletions patchwork/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -126,8 +130,20 @@ 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)