Skip to content

Commit

Permalink
prsync: support downloading
Browse files Browse the repository at this point in the history
fixes #120
  • Loading branch information
lilydjwg committed Mar 24, 2021
1 parent c33a7fe commit c4d0b9a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions bin/prsync
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def option_parser():
help='use rsync compression (OPTIONAL)')
parser.add_option('-S', '--ssh-args', metavar="ARGS", dest='ssh_args',
action='store', help='extra arguments for ssh')
parser.add_option('-d', '--download', dest='download', action='store_true',
help='download files instead, reversing local and remote (OPTIONAL)')

return parser

Expand Down Expand Up @@ -83,11 +85,22 @@ def do_prsync(hosts, local, remote, opts):
cmd.append('-z')
if opts.extra:
cmd.extend(opts.extra)
cmd.extend(local)
if user:
cmd.append('%s@%s:%s' % (user, host, remote))
if opts.download:
if len(local) != 1:
sys.exit('can only download one target at a time')
if user:
cmd.append('%s@%s:%s' % (user, host, local[0]))
else:
cmd.append('%s:%s' % (host, local[0]))
localpath = "%s/%s" % (remote, host)
os.makedirs(localpath)
cmd.append(localpath)
else:
cmd.append('%s:%s' % (host, remote))
cmd.extend(local)
if user:
cmd.append('%s@%s:%s' % (user, host, remote))
else:
cmd.append('%s:%s' % (host, remote))
t = Task(host, port, user, cmd, opts)
manager.add_task(t)
try:
Expand Down

0 comments on commit c4d0b9a

Please sign in to comment.