mirror of https://gitlab.com/KKlochko/tui-rsync
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.0 KiB
78 lines
3.0 KiB
################################################################################
|
|
# 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
|
|
from rich.prompt import Prompt
|
|
from typing import List, Optional
|
|
import typer
|
|
|
|
from models.models import Source, Destination, SyncCommand, Path
|
|
from models.models import all_labels
|
|
from cli.label_prompt import LabelPrompt
|
|
from cli.path_prompt import PathPrompt
|
|
from cli.rsync import Rsync
|
|
|
|
console = Console()
|
|
sync = typer.Typer()
|
|
|
|
@sync.command()
|
|
def one(
|
|
label: str = typer.Option(
|
|
None, "--label", "-l",
|
|
help="[b]The label[/] is a uniq identification of a [b]source[/].",
|
|
show_default=False
|
|
),
|
|
):
|
|
"""
|
|
[green b]Sync[/] a [yellow]source[/] with the [yellow b]label[/] and its backups.
|
|
"""
|
|
if label is None:
|
|
label = LabelPrompt.get_label_fzf()
|
|
src = Source.get(Source.label == label)
|
|
rsync = Rsync(str(src.args))
|
|
for dest in src.destinations:
|
|
rsync.run_one(str(src.source), str(dest))
|
|
|
|
@sync.command()
|
|
def all():
|
|
"""
|
|
[green b]Sync[/] [yellow]all sources[/] with theirs backups.
|
|
"""
|
|
for label in all_labels().iterator():
|
|
one(label.label)
|
|
|
|
@sync.command()
|
|
def recover(
|
|
label: str = typer.Option(
|
|
None, "--label", "-l",
|
|
help="[b]The label[/] is a uniq identification of a [b]source[/].",
|
|
show_default=False
|
|
),
|
|
):
|
|
"""
|
|
[green b]Sync[/] the [yellow]chosen backup[/] with its source.
|
|
"""
|
|
if label is None:
|
|
label = LabelPrompt.get_label_fzf()
|
|
src = Source.get(Source.label == label)
|
|
dest = PathPrompt.get_backup_fzf(label)
|
|
|
|
rsync = Rsync(str(src.args))
|
|
rsync.run_one(str(dest), str(src.source))
|