diff --git a/tui_rsync/core/shared_kernel/components/backup/__init__.py b/tui_rsync/core/shared_kernel/components/backup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tui_rsync/core/shared_kernel/components/backup/application/__init__.py b/tui_rsync/core/shared_kernel/components/backup/application/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tui_rsync/core/shared_kernel/components/backup/application/service/__init__.py b/tui_rsync/core/shared_kernel/components/backup/application/service/__init__.py new file mode 100644 index 0000000..007a580 --- /dev/null +++ b/tui_rsync/core/shared_kernel/components/backup/application/service/__init__.py @@ -0,0 +1,3 @@ +from .backup_sync_service import BackupSyncService + +__all__ = ['BackupSyncService'] diff --git a/tui_rsync/core/shared_kernel/components/backup/application/service/backup_sync_service.py b/tui_rsync/core/shared_kernel/components/backup/application/service/backup_sync_service.py new file mode 100644 index 0000000..d9ba904 --- /dev/null +++ b/tui_rsync/core/shared_kernel/components/backup/application/service/backup_sync_service.py @@ -0,0 +1,20 @@ +from tui_rsync.core.components.backup.application.backup_commands import BackupSyncCommand, BackupSyncCommandDryRun +from tui_rsync.core.components.backup_plan.application.repository import BackupPlanRepositoryPort +from tui_rsync.core.shared_kernel.components.common import UUID + + +class BackupSyncService: + def __init__(self, backup_plan_repository: BackupPlanRepositoryPort): + self.backup_plan_repository = backup_plan_repository + + def sync_by_plan_id(self, uuid: UUID, args: str = '', dry_run: bool = False): + backup_plan = self.backup_plan_repository.get_by_id(uuid) + + if dry_run: + for destination in backup_plan.destinations: + backup_command = BackupSyncCommandDryRun(backup_plan.source.path, destination.path, args) + backup_command.run() + else: + for destination in backup_plan.destinations: + backup_command = BackupSyncCommand(backup_plan.source.path, destination.path, args) + backup_command.run() diff --git a/tui_rsync/infrastructure/configuration/configuration.py b/tui_rsync/infrastructure/configuration/configuration.py index d5f3a79..361ea96 100644 --- a/tui_rsync/infrastructure/configuration/configuration.py +++ b/tui_rsync/infrastructure/configuration/configuration.py @@ -7,6 +7,7 @@ from tui_rsync.core.components.backup_plan.application.repository.backup_plan_re from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService from tui_rsync.core.ports.configuration import UserDataPathsPort from tui_rsync.core.ports.orm import DatabaseManagerPort +from tui_rsync.core.shared_kernel.components.backup.application.service import BackupSyncService from tui_rsync.infrastructure.configuration import UserDataPaths from tui_rsync.infrastructure.orm import SqliteDatabaseManager @@ -41,3 +42,8 @@ class Configuration(Module): @singleton def provide_get_all_backup_backup_plans_query(self, database_manager: DatabaseManagerPort) -> GetAllBackupBackupPlansQuery: return GetAllBackupBackupPlansQuery(database_manager) + + @provider + @singleton + def provide_backup_sync_service(self, backup_plan_repository: BackupPlanRepositoryPort) -> BackupSyncService: + return BackupSyncService(backup_plan_repository)