mirror of https://gitlab.com/KKlochko/tui-rsync
parent
87682a056f
commit
b32e5d32b0
@ -0,0 +1,22 @@
|
|||||||
|
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
|
||||||
|
from tui_rsync.user_interface.cli.shared_kernel.components.prompts.applications.prompts import ChoosePromptPort
|
||||||
|
|
||||||
|
|
||||||
|
class BackupRestoreService:
|
||||||
|
def __init__(self, backup_plan_repository: BackupPlanRepositoryPort):
|
||||||
|
self.backup_plan_repository = backup_plan_repository
|
||||||
|
|
||||||
|
def sync_by_plan_id(self, uuid: UUID, choose_prompt: ChoosePromptPort, args: str = '', dry_run: bool = False):
|
||||||
|
backup_plan = self.backup_plan_repository.get_by_id(uuid)
|
||||||
|
|
||||||
|
destinations = (destination.path for destination in backup_plan.destinations)
|
||||||
|
destination = choose_prompt.choose(destinations)
|
||||||
|
|
||||||
|
if dry_run:
|
||||||
|
backup_command = BackupSyncCommandDryRun(destination, backup_plan.source.path, args)
|
||||||
|
backup_command.run()
|
||||||
|
else:
|
||||||
|
backup_command = BackupSyncCommand(destination, backup_plan.source.path, args)
|
||||||
|
backup_command.run()
|
@ -0,0 +1,4 @@
|
|||||||
|
from .choose_prompt_port import ChoosePromptPort
|
||||||
|
from .fzf_prompt import ChoosePromptFzf
|
||||||
|
|
||||||
|
__all__ = ['ChoosePromptPort', 'ChoosePromptFzf']
|
@ -0,0 +1,8 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class ChoosePromptPort(ABC):
|
||||||
|
@staticmethod
|
||||||
|
@abstractmethod
|
||||||
|
def choose(iterator) -> str:
|
||||||
|
pass
|
@ -0,0 +1,9 @@
|
|||||||
|
from .choose_prompt_port import ChoosePromptPort
|
||||||
|
from pyfzf import FzfPrompt
|
||||||
|
|
||||||
|
|
||||||
|
class ChoosePromptFzf(ChoosePromptPort):
|
||||||
|
@staticmethod
|
||||||
|
def choose(iterator) -> str:
|
||||||
|
fzf = FzfPrompt()
|
||||||
|
return fzf.prompt(iterator)[0]
|
Loading…
Reference in new issue