(Added) source update args function.

dev
KKlochko 2 years ago
parent b99f2a0ffa
commit c063b5a82c

@ -6,7 +6,9 @@
Added *sync one* function. Added *sync one* function.
Added Rsync wrappper. Added Rsync wrappper.
Added fzf_prompt, all_labels for choosing a label of source. Added fzf_prompt, all_labels for choosing a label of source.
** 0.3.5 <2023-03-01> ** 0.3.5 <2023-03-01 Wed>
Added *sync all* function. Added *sync all* function.
Added all_labels_except for choosing many labels. Added all_labels_except for choosing many labels.
Added fzf function for using all_labels_except. Added fzf function for using all_labels_except.
** 0.4.1 <2023-03-02 Thu>
Added *source update args* function.

@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "tui-rsync" name = "tui-rsync"
version = "0.1.0" version = "0.4.1"
description = "" description = ""
authors = ["Kostiantyn Klochko <kostya_klochko@ukr.net>"] authors = ["Kostiantyn Klochko <kostya_klochko@ukr.net>"]
readme = "README.rst" readme = "README.rst"

@ -24,9 +24,11 @@ import typer
from models.models import Source, Destination, SyncCommand, Path from models.models import Source, Destination, SyncCommand, Path
from cli.label_prompt import LabelPrompt from cli.label_prompt import LabelPrompt
from cli.source_update import source_update
console = Console() console = Console()
source = typer.Typer() source = typer.Typer()
source.add_typer(source_update, name="update", help="Update sources")
@source.command() @source.command()
def add( def add(
@ -53,7 +55,7 @@ def add(
""" """
[green b]Create[/] a [yellow]new source[/] with a [bold]uniq[/] label. [green b]Create[/] a [yellow]new source[/] with a [bold]uniq[/] label.
[b]The source[/] will be connected to [b]backup destinations[/]. [b]The source[/] will be connected to [b]backup destinations[/].
[yellow i]Optionally, additional[/] arguments for rsync can be added.g [yellow i]Optionally, additional[/] arguments for rsync can be added.
""" """
if label is None: if label is None:
label = LabelPrompt.ask_uuid() label = LabelPrompt.ask_uuid()

@ -0,0 +1,54 @@
################################################################################
# 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 cli.label_prompt import LabelPrompt
console = Console()
source_update = typer.Typer()
@source_update.command()
def args(
label: str = typer.Option(
None, "--label", "-l",
help="[b]The label[/] is a uniq identification of a [b]source[/].",
show_default=False
),
args: str = typer.Option(
None, "--args", "-a",
help="[b yellow]rsync[/] [b]arguments[/].",
show_default=False
)
):
"""
[green b]Update[/] an [yellow]existing source args[/].
"""
if args is None:
args = console.input("What is the [yellow b]rsync args of source[/]? ")
if Source.is_exist(label):
src = Source.get_source(label)
src.update_args(args)

@ -37,6 +37,11 @@ class Path(BaseModel):
class SyncCommand(BaseModel): class SyncCommand(BaseModel):
command = CharField() command = CharField()
@staticmethod
def get_sync_command(args):
sync_cmd, _ = SyncCommand.get_or_create(command=args)
return sync_cmd
def __str__(self) -> str: def __str__(self) -> str:
return self.command return self.command
@ -45,6 +50,16 @@ class Source(BaseModel):
source = ForeignKeyField(Path) source = ForeignKeyField(Path)
args = ForeignKeyField(SyncCommand) args = ForeignKeyField(SyncCommand)
@staticmethod
def is_exist(label) -> bool:
return Source.select().where(Source.label == label).exists()
@staticmethod
def get_source(label):
if not Source.is_exist(label):
return None
return Source.select().where(Source.label == label).get()
@staticmethod @staticmethod
def create_save(label:str, source:str, destinations:list[str], args:str): def create_save(label:str, source:str, destinations:list[str], args:str):
src_path, _ = Path.get_or_create(path=source) src_path, _ = Path.get_or_create(path=source)
@ -61,6 +76,11 @@ class Source(BaseModel):
src.save() src.save()
return src return src
def update_args(self, args):
args_obj = SyncCommand.get_sync_command(args)
self.args = args_obj
self.save()
def __str__(self) -> str: def __str__(self) -> str:
return f"{self.label}" return f"{self.label}"

Loading…
Cancel
Save