mirror of https://gitlab.com/KKlochko/tui-rsync
parent
b9564d75e7
commit
ea5d98490d
@ -0,0 +1,3 @@
|
||||
from .backup_plan_format import BackupPlanFormat
|
||||
|
||||
__all__ = ['BackupPlanFormat']
|
@ -0,0 +1,39 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2023-2025 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 tui_rsync.core.components.backup_plan.domain import BackupPlan
|
||||
|
||||
|
||||
class BackupPlanFormat:
|
||||
@staticmethod
|
||||
def format(backup_plan: BackupPlan, prefix='') -> str:
|
||||
output = f"[b]uuid:[/] {backup_plan.id.id}\n" \
|
||||
f"[b]label:[/] {backup_plan.label}\n" \
|
||||
f"[b]source:[/] {backup_plan.source.path}\n" \
|
||||
f"[b]destionations:[/] \n"
|
||||
|
||||
for destination in backup_plan.destinations:
|
||||
output += f"\t{destination.path}\n"
|
||||
|
||||
if prefix != '':
|
||||
keepends = True
|
||||
output = prefix + f'{prefix}'.join(output.splitlines(keepends))
|
||||
|
||||
return output
|
@ -0,0 +1,74 @@
|
||||
################################################################################
|
||||
# Copyright (C) 2023-2025 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.Queries import GetAllBackupBackupPlansQuery
|
||||
|
||||
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
|
||||
from tui_rsync.user_interface.cli.components.backup_plan.formating import BackupPlanFormat
|
||||
|
||||
console = Console()
|
||||
show_backup_plan = typer.Typer()
|
||||
|
||||
|
||||
@show_backup_plan.command()
|
||||
def one(
|
||||
id: str = typer.Option(
|
||||
None, "--id", "-i",
|
||||
help="[b]The label[/] is a uniq identification of a [b]source[/].",
|
||||
show_default=False
|
||||
),
|
||||
):
|
||||
"""
|
||||
[green b]Show[/] an [yellow]existing backup plan by the id[/].
|
||||
"""
|
||||
|
||||
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.get_by_id(UUID(id))
|
||||
|
||||
if plan is None:
|
||||
console.print("[red b][ERROR][/] Backup plan does not exists!!!")
|
||||
return
|
||||
|
||||
console.print(BackupPlanFormat.format(plan))
|
||||
|
||||
|
||||
@show_backup_plan.command()
|
||||
def all():
|
||||
"""
|
||||
[green b]Show[/] [yellow]all existing backup plans[/].
|
||||
"""
|
||||
|
||||
db = SqliteDatabaseManager()
|
||||
query = GetAllBackupBackupPlansQuery()
|
||||
|
||||
for backup_plan in query.execute():
|
||||
console.print(BackupPlanFormat.format(backup_plan))
|
Loading…
Reference in new issue