Add a progress bar for rsync
On a terminal, run rsync with --info=progress2 and draw its updates as a progress bar on stderr. The ETA is estimated locally, since rsync reports the elapsed time when a file finishes. Disable it with --no-progress.
This commit is contained in:
+14
-1
@@ -27,7 +27,7 @@ class FakeBackup:
|
||||
def __init__(self, inputs: Any, output: Any, exclude: Any, keep: Any, options: str,
|
||||
ssh_host: Optional[str] = None, ssh_user: Optional[str] = None,
|
||||
ssh_keyfile: Optional[str] = None, remote_sudo: bool = False,
|
||||
remove_before: bool = False, verbose: bool = False) -> None:
|
||||
remove_before: bool = False, verbose: bool = False, progress: bool = False) -> None:
|
||||
self.inputs = inputs
|
||||
self.output = output
|
||||
self.exclude = exclude
|
||||
@@ -39,6 +39,7 @@ class FakeBackup:
|
||||
self.remote_sudo = remote_sudo
|
||||
self.remove_before = remove_before
|
||||
self.verbose = verbose
|
||||
self.progress = progress
|
||||
self.homedir: Optional[str] = None
|
||||
self.ran = False
|
||||
self.closed = False
|
||||
@@ -224,6 +225,18 @@ ssh_keyfile=/keys/id
|
||||
b = last_backup()
|
||||
assert b.remote_sudo and b.remove_before and b.verbose
|
||||
|
||||
@pytest.mark.parametrize('tty, argv, progress', [
|
||||
(True, [], True),
|
||||
(True, ['--no-progress'], False),
|
||||
(False, [], False),
|
||||
])
|
||||
def test_progress(self, run_cli: RunCli, config: Callable[[str], str], monkeypatch: pytest.MonkeyPatch,
|
||||
tty: bool, argv: list[str], progress: bool) -> None:
|
||||
monkeypatch.setattr(sb.sys.stderr, 'isatty', lambda: tty)
|
||||
|
||||
assert run_cli('-c', config('backup_dir=/backups'), *argv) == 0
|
||||
assert last_backup().progress is progress
|
||||
|
||||
def test_check_params_failure(self, run_cli: RunCli, config: Callable[[str], str]) -> None:
|
||||
FakeBackup.check_code = 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user