mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-09-09 06:57:44 +00:00
Add the remove commands.
Fixed deleting to remove destinations with a backup plan.
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
from .remove_all_backup_plans_command import RemoveAllBackupBackupPlansCommand
|
||||||
|
|
||||||
|
__all__ = ['RemoveAllBackupBackupPlansCommand']
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
||||||
|
|
||||||
|
|
||||||
|
class RemoveAllBackupBackupPlansCommand:
|
||||||
|
def execute(self) -> bool:
|
||||||
|
rows = BackupPlanModel.delete().execute()
|
||||||
|
rows = DestinationModel.delete().execute() + rows
|
||||||
|
return rows != 0
|
||||||
+2
-1
@@ -7,7 +7,7 @@ from .backup_plan_repository_port import BackupPlanRepositoryPort
|
|||||||
from tui_rsync.core.components.backup_plan.domain import BackupPlan
|
from tui_rsync.core.components.backup_plan.domain import BackupPlan
|
||||||
from tui_rsync.core.shared_kernel.components.common import UUID
|
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||||
|
|
||||||
from tui_rsync.infrastructure.orm.models import BackupPlanModel
|
from tui_rsync.infrastructure.orm.models import BackupPlanModel, DestinationModel
|
||||||
|
|
||||||
|
|
||||||
class BackupPlanRepository(BackupPlanRepositoryPort):
|
class BackupPlanRepository(BackupPlanRepositoryPort):
|
||||||
@@ -34,4 +34,5 @@ class BackupPlanRepository(BackupPlanRepositoryPort):
|
|||||||
|
|
||||||
def delete(self, uuid: UUID) -> bool:
|
def delete(self, uuid: UUID) -> bool:
|
||||||
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
|
deleted = BackupPlanModel.delete().where(BackupPlanModel.id == uuid.id).execute()
|
||||||
|
deleted = DestinationModel.delete().where(DestinationModel.source == uuid.id).execute() | deleted
|
||||||
return bool(deleted)
|
return bool(deleted)
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
import typer
|
import typer
|
||||||
from .add_backup_plan import add_backup_plan
|
from .add_backup_plan import add_backup_plan
|
||||||
from .show_backup_plan import show_backup_plan
|
from .show_backup_plan import show_backup_plan
|
||||||
|
from .remove_backup_plan import remove_backup_plan
|
||||||
|
|
||||||
|
|
||||||
backup_plan = add_backup_plan
|
backup_plan = add_backup_plan
|
||||||
backup_plan.add_typer(show_backup_plan, name="show", help="Show backup plans")
|
backup_plan.add_typer(show_backup_plan, name="show", help="Show backup plans")
|
||||||
|
backup_plan.add_typer(remove_backup_plan, name="remove", help="Remove backup plans")
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
################################################################################
|
||||||
|
# Copyright (C) 2023 Kostiantyn Klochko <kostya_klochko@ukr.net> #
|
||||||
|
# #
|
||||||
|
# This file is part of tui-rsync. #
|
||||||
|
# #
|
||||||
|
# tui-rsync is free software: you can redistribute it and/or modify it under #
|
||||||
|
# uthe terms of the GNU General Public License as published by the Free #
|
||||||
|
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||||
|
# any later version. #
|
||||||
|
# #
|
||||||
|
# tui-rsync is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||||
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more #
|
||||||
|
# details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License along with #
|
||||||
|
# tui-rsync. If not, see <https://www.gnu.org/licenses/>. #
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
from rich.console import Console
|
||||||
|
import typer
|
||||||
|
|
||||||
|
from tui_rsync.core.components.backup_plan.application.commands import RemoveAllBackupBackupPlansCommand
|
||||||
|
from tui_rsync.core.components.backup_plan.application.repository.backup_plan_repository import BackupPlanRepository
|
||||||
|
from tui_rsync.core.components.backup_plan.application.services.backup_plan_service import BackupPlanService
|
||||||
|
from tui_rsync.core.shared_kernel.components.common import UUID
|
||||||
|
from tui_rsync.infrastructure.orm import SqliteDatabaseManager
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
remove_backup_plan = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
|
@remove_backup_plan.command()
|
||||||
|
def one(
|
||||||
|
id: str = typer.Option(
|
||||||
|
None, "--id", "-i",
|
||||||
|
help="[b]The id[/] is an uniq identification of a [b]backup plan[/].",
|
||||||
|
show_default=False
|
||||||
|
)
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
[red b]Remove[/] an [yellow]existing backup plan[/].
|
||||||
|
"""
|
||||||
|
|
||||||
|
db = SqliteDatabaseManager()
|
||||||
|
repository = BackupPlanRepository(db)
|
||||||
|
service = BackupPlanService(repository)
|
||||||
|
|
||||||
|
if id is None:
|
||||||
|
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
||||||
|
return
|
||||||
|
|
||||||
|
plan = service.delete(UUID(id))
|
||||||
|
|
||||||
|
if plan is None:
|
||||||
|
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
||||||
|
return
|
||||||
|
|
||||||
|
console.print(f"Removed the backup plan with {id}.")
|
||||||
|
|
||||||
|
|
||||||
|
@remove_backup_plan.command()
|
||||||
|
def all():
|
||||||
|
"""
|
||||||
|
[red b]Remove[/] [yellow] all existing backup plans[/].
|
||||||
|
"""
|
||||||
|
|
||||||
|
db = SqliteDatabaseManager()
|
||||||
|
removed = RemoveAllBackupBackupPlansCommand().execute()
|
||||||
|
|
||||||
|
if removed:
|
||||||
|
console.print(f"Removed all backup plans.")
|
||||||
|
else:
|
||||||
|
console.print(f"Nothing to remove. No backup plans.")
|
||||||
Reference in New Issue
Block a user