Skip to content

Commit d10482a

Browse files
committed
Fix 26 to support remote to local copying as well as local to remote.
Issue support rsync from remote to local fabric#38 Adds the flag remote_to_local to rsync(), defaults to False so that local copy remains the default. From @https://github.com/MacHu-GWU patch fabric#38 (comment)
1 parent 1207916 commit d10482a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/patchwork/transfers.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def rsync(
1212
strict_host_keys=True,
1313
rsync_opts="",
1414
ssh_opts="",
15+
remote_to_local=False,
1516
):
1617
"""
1718
Convenient wrapper around your friendly local ``rsync``.
@@ -121,11 +122,18 @@ def rsync(
121122
options = f"{options_map['delete']}{options_map['exclude']} -pthrvz {options_map['extra']} {options_map['rsh']}"
122123
# Create and run final command string
123124
# TODO: richer host object exposing stuff like .address_is_ipv6 or whatever
124-
if host.count(":") > 1:
125+
if host.count(":") > 1:
125126
# Square brackets are mandatory for IPv6 rsync address,
126127
# even if port number is not specified
127-
cmd = "rsync {} {} [{}@{}]:{}"
128+
# Patch to enable remote to local copying
129+
if remote_to_local:
130+
cmd = "rsync {options} [{user}@{host}]:{target} {source}"
131+
else:
132+
cmd = "rsync {options} {source} [{user}@{host}]:{target}"
128133
else:
129-
cmd = "rsync {} {} {}@{}:{}"
130-
cmd = cmd.format(options, source, user, host, target)
131-
return c.local(cmd)
134+
if remote_to_local:
135+
cmd = "rsync {options} {user}@{host}:{target} {source}"
136+
else:
137+
cmd = "rsync {options} {source} {user}@{host}:{target}"
138+
cmd = cmd.format(options=options, source=source, user=user, host=host, target=target)
139+
return c.local(cmd)

0 commit comments

Comments
 (0)