From f708cdf3d424e37b9b8665c3a965564aebf796bb Mon Sep 17 00:00:00 2001 From: KKlochko Date: Wed, 15 Jan 2025 21:08:16 +0200 Subject: [PATCH] Add the backup commands to sync the data. --- tui_rsync/core/components/backup/__init__.py | 0 .../core/components/backup/application/__init__.py | 5 +++++ .../backup/application/backup_command_port.py | 7 +++++++ .../backup/application/backup_sync_command.py | 14 ++++++++++++++ .../application/backup_sync_command_dry_run.py | 14 ++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 tui_rsync/core/components/backup/__init__.py create mode 100644 tui_rsync/core/components/backup/application/__init__.py create mode 100644 tui_rsync/core/components/backup/application/backup_command_port.py create mode 100644 tui_rsync/core/components/backup/application/backup_sync_command.py create mode 100644 tui_rsync/core/components/backup/application/backup_sync_command_dry_run.py diff --git a/tui_rsync/core/components/backup/__init__.py b/tui_rsync/core/components/backup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tui_rsync/core/components/backup/application/__init__.py b/tui_rsync/core/components/backup/application/__init__.py new file mode 100644 index 0000000..7a1faf9 --- /dev/null +++ b/tui_rsync/core/components/backup/application/__init__.py @@ -0,0 +1,5 @@ +from .backup_command_port import BackupCommandPort +from .backup_sync_command import BackupSyncCommand +from .backup_sync_command_dry_run import BackupSyncCommandDryRun + +__all__ = ['BackupCommandPort', 'BackupSyncCommand', 'BackupSyncCommandDryRun'] diff --git a/tui_rsync/core/components/backup/application/backup_command_port.py b/tui_rsync/core/components/backup/application/backup_command_port.py new file mode 100644 index 0000000..ec32a1c --- /dev/null +++ b/tui_rsync/core/components/backup/application/backup_command_port.py @@ -0,0 +1,7 @@ +from abc import ABC, abstractmethod + + +class BackupCommandPort(ABC): + @abstractmethod + def run(self): + pass diff --git a/tui_rsync/core/components/backup/application/backup_sync_command.py b/tui_rsync/core/components/backup/application/backup_sync_command.py new file mode 100644 index 0000000..a55963c --- /dev/null +++ b/tui_rsync/core/components/backup/application/backup_sync_command.py @@ -0,0 +1,14 @@ +import shlex +from subprocess import Popen, PIPE + +from . import BackupCommandPort + + +class BackupSyncCommand(BackupCommandPort): + def __init__(self, source: str, destination: str, args: str): + self._args = ["rsync"] + shlex.split(args) + [source, destination] + + def run(self): + output = Popen(self._args, stdout=PIPE) + response = output.communicate() + diff --git a/tui_rsync/core/components/backup/application/backup_sync_command_dry_run.py b/tui_rsync/core/components/backup/application/backup_sync_command_dry_run.py new file mode 100644 index 0000000..4f5d2b8 --- /dev/null +++ b/tui_rsync/core/components/backup/application/backup_sync_command_dry_run.py @@ -0,0 +1,14 @@ +import shlex +from subprocess import Popen, PIPE + +from . import BackupCommandPort + + +class BackupSyncCommandDryRun(BackupCommandPort): + def __init__(self, source: str, destination: str, args: str): + self._args = ["rsync"] + shlex.split(args) + ['--dry-run', source, destination] + + def run(self): + output = Popen(self._args, stdout=PIPE) + return output.communicate() +