diff --git a/README.md b/README.md index 5f2610e..1ccb67c 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/sysrsync/command_maker.py b/sysrsync/command_maker.py index d60d300..e2f5db3 100644 --- a/sysrsync/command_maker.py +++ b/sysrsync/command_maker.py @@ -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() @@ -38,7 +40,7 @@ def get_rsync_command(source: str, if options is None: options = [] - return ['rsync', + return [rsync_cmd, *options, *rsh, source, diff --git a/sysrsync/runner.py b/sysrsync/runner.py index 8f5b141..017fc79 100644 --- a/sysrsync/runner.py +++ b/sysrsync/runner.py @@ -1,6 +1,6 @@ import os import subprocess - +import inspect from sysrsync.command_maker import get_rsync_command from sysrsync.exceptions import RsyncError @@ -8,11 +8,15 @@ 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 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