diff --git a/rattail_fabric2/core.py b/rattail_fabric2/core.py index 97cd616..176ecc8 100644 --- a/rattail_fabric2/core.py +++ b/rattail_fabric2/core.py @@ -352,13 +352,21 @@ def make_deploy(deploy_path, last_segment='deploy'): return Deployer(deploy_path, last_segment) -def rsync(c, host, *paths): +def rsync(c, host, *paths, files=False, target=None): """ Runs rsync as root, for the given host and file paths. + + :param files: If set, this indicates that each of the ``paths`` + are actual files, as opposed to directories. + + :param target: If set, this will be used instead of the given + path, for destination path. This only works correctly if + ``paths`` contains only one path. """ for path in paths: assert path.startswith('/') path = path.rstrip('/') # escape path for rsync path = path.replace(' ', r'\\\ ').replace("'", r"\\\'") - agent_sudo(c, 'rsync -aP --del root@{0}:{1}/ {1}'.format(host, path)) + suffix = '' if files else '/' + agent_sudo(c, f'rsync -aP --del root@{host}:{path}{suffix} {target or path}')