From c4d0b9a94d8b20e4b26b622951f783ca86ea46be Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 24 Mar 2021 17:12:24 +0800 Subject: [PATCH] prsync: support downloading fixes #120 --- bin/prsync | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/prsync b/bin/prsync index 4cfaf4e..b79626f 100755 --- a/bin/prsync +++ b/bin/prsync @@ -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 @@ -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: