Skip to content

Add from_local option to transfers.rsync #29

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 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions patchwork/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def rsync(
c,
source,
target,
from_local=True,
exclude=(),
delete=False,
strict_host_keys=True,
Expand Down Expand Up @@ -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 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``.
Expand Down Expand Up @@ -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, source, user, host, target)
else:
cmd = "rsync {} {} {}@{}:{}"
cmd = cmd.format(options, source, user, host, target)
cmd = "rsync {} " + cmd_remote + ":{} {}"
cmd = cmd.format(options, user, host, source, target)
return c.local(cmd)