mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
(Added) sync recover function.
Fixed label_prompt returning list.
This commit is contained in:
@@ -40,9 +40,9 @@ class LabelPrompt:
|
||||
@staticmethod
|
||||
def get_label_fzf() -> str:
|
||||
fzf = FzfPrompt()
|
||||
return fzf.prompt(all_labels().iterator())
|
||||
return fzf.prompt(all_labels().iterator())[0]
|
||||
|
||||
@staticmethod
|
||||
def get_label_except_fzf(labels = None) -> str:
|
||||
fzf = FzfPrompt()
|
||||
return fzf.prompt(all_labels_except(labels).iterator())
|
||||
return fzf.prompt(all_labels_except(labels).iterator())[0]
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
################################################################################
|
||||
# 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 the 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 sys import stderr
|
||||
from rich.console import Console
|
||||
from rich.prompt import Prompt
|
||||
from pyfzf import FzfPrompt
|
||||
import os
|
||||
from models.models import Destination
|
||||
|
||||
console = Console()
|
||||
err_console = Console(stderr=True)
|
||||
|
||||
class PathPrompt:
|
||||
@staticmethod
|
||||
def get_backup_fzf(label:str) -> str:
|
||||
dests_count = len(Destination.get_all(label))
|
||||
if dests_count == 0:
|
||||
err_console.print("[red b]No backups!!![/]")
|
||||
return ""
|
||||
if dests_count == 1:
|
||||
return Destination.get_all(label).get()
|
||||
fzf = FzfPrompt()
|
||||
return fzf.prompt(Destination.get_all(label).iterator())[0]
|
||||
@@ -25,6 +25,7 @@ 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()
|
||||
@@ -55,3 +56,22 @@ def all():
|
||||
"""
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user