Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ sysrsync.run(source='/home/user/files',
| sync_source_contents | bool | True | Abstracts the elusive trailing slash behaviour that `source` normally has when using rsync directly, i.e. when a trailing slash is present in `source`, the folder's content is synchronized with destination. When no trailing slash is present, the folder itself is synchronized with destination. |
| options | Optional[Iterable[str]] | None | List of options to be used right after rsync call, e.g. `['-a', '-v']` translates to `rsync -a -v` |
| private_key | Optional[str] | None | Configures an explicit key to be used with rsync --rsh command |
| rsync_binary | Optional[str] | rsync | The rsync binary to call |
| **kwargs | dict | Not Applicable | arguments that will be forwarded to call to `subprocess.Popen` |

**returns**: `List[str]` -> the compiled list of commands to be used directly in `subprocess.run`

Expand Down
6 changes: 4 additions & 2 deletions sysrsync/command_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def get_rsync_command(source: str,
exclusions: Optional[Iterable[str]] = None,
sync_source_contents: bool = True,
options: Optional[Iterable[str]] = None,
private_key: Optional[str] = None) -> List[str]:
private_key: Optional[str] = None,
rsync_binary: Optional[str] = 'rsync',
**kwargs) -> List[str]:
if source_ssh is not None and destination_ssh is not None:
raise RemotesError()

Expand All @@ -38,7 +40,7 @@ def get_rsync_command(source: str,
if options is None:
options = []

return ['rsync',
return [rsync_cmd,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the argument is called rsync_binary, but here, it is rsync_cmd

*options,
*rsh,
source,
Expand Down
10 changes: 7 additions & 3 deletions sysrsync/runner.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import os
import subprocess

import inspect
from sysrsync.command_maker import get_rsync_command
from sysrsync.exceptions import RsyncError


def run(cwd=os.getcwd(), strict=True, verbose=False, **kwargs):
rsync_command = get_rsync_command(**kwargs)
rsync_string = ' '.join(rsync_command)

rsync_args = inspect.getfullargspec(get_rsync_command)[0]
subp_kwargs = {}
for k, v in kwargs.items():
if k not in rsync_args:
subp_kwargs[k] = v
Comment on lines +11 to +15
Copy link
Owner

@gchamon gchamon May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe to avoid risking get_rsync_command and subprocess.run arguments collision, we could add a separate argument for sysrsync.run to pass those args to subprocess.run?

if verbose is True:
print(f'[sysrsync runner] running command on "{cwd}":')
print(rsync_string)
process = subprocess.run(rsync_string, cwd=cwd, shell=True)
process = subprocess.run(rsync_string, cwd=cwd, shell=True, **subp_kwargs)

if strict is True:
code = process.returncode
Expand Down