mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-09-09 06:57:44 +00:00
(Added) sync recover function.
Fixed label_prompt returning list.
This commit is contained in:
@@ -14,3 +14,6 @@
|
|||||||
Added *source update args* function.
|
Added *source update args* function.
|
||||||
** 0.5.0 <2023-03-03 Fri>
|
** 0.5.0 <2023-03-03 Fri>
|
||||||
Added *groups add* function.
|
Added *groups add* function.
|
||||||
|
** 0.5.2 <2023-03-04 Sat>
|
||||||
|
Added *sync recover* function.
|
||||||
|
Fixed label_prompt returning list.
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ class LabelPrompt:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_label_fzf() -> str:
|
def get_label_fzf() -> str:
|
||||||
fzf = FzfPrompt()
|
fzf = FzfPrompt()
|
||||||
return fzf.prompt(all_labels().iterator())
|
return fzf.prompt(all_labels().iterator())[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_label_except_fzf(labels = None) -> str:
|
def get_label_except_fzf(labels = None) -> str:
|
||||||
fzf = FzfPrompt()
|
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 Source, Destination, SyncCommand, Path
|
||||||
from models.models import all_labels
|
from models.models import all_labels
|
||||||
from cli.label_prompt import LabelPrompt
|
from cli.label_prompt import LabelPrompt
|
||||||
|
from cli.path_prompt import PathPrompt
|
||||||
from cli.rsync import Rsync
|
from cli.rsync import Rsync
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
@@ -55,3 +56,22 @@ def all():
|
|||||||
"""
|
"""
|
||||||
for label in all_labels().iterator():
|
for label in all_labels().iterator():
|
||||||
one(label.label)
|
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))
|
||||||
|
|||||||
@@ -93,6 +93,19 @@ class Destination(BaseModel):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"{self.path}"
|
return f"{self.path}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_all(label:str|None = None):
|
||||||
|
"""
|
||||||
|
Return all destiantions of the source.
|
||||||
|
"""
|
||||||
|
if label is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
src = Source.get_source(label)
|
||||||
|
if src is None:
|
||||||
|
return []
|
||||||
|
return src.destinations
|
||||||
|
|
||||||
class Group(BaseModel):
|
class Group(BaseModel):
|
||||||
label = CharField(unique=True)
|
label = CharField(unique=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user