diff --git a/CHANGELOG.org b/CHANGELOG.org index 0205af5..7f77b1c 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -6,7 +6,9 @@ Added *sync one* function. Added Rsync wrappper. 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 all_labels_except for choosing many labels. Added fzf function for using all_labels_except. +** 0.4.1 <2023-03-02 Thu> + Added *source update args* function. diff --git a/pyproject.toml b/pyproject.toml index 2b08688..e32f854 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "tui-rsync" -version = "0.1.0" +version = "0.4.1" description = "" authors = ["Kostiantyn Klochko "] readme = "README.rst" diff --git a/tui_rsync/cli/source.py b/tui_rsync/cli/source.py index cba9cdc..e80e818 100644 --- a/tui_rsync/cli/source.py +++ b/tui_rsync/cli/source.py @@ -24,9 +24,11 @@ import typer from models.models import Source, Destination, SyncCommand, Path from cli.label_prompt import LabelPrompt +from cli.source_update import source_update console = Console() source = typer.Typer() +source.add_typer(source_update, name="update", help="Update sources") @source.command() def add( @@ -53,7 +55,7 @@ def add( """ [green b]Create[/] a [yellow]new source[/] with a [bold]uniq[/] label. [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: label = LabelPrompt.ask_uuid() diff --git a/tui_rsync/cli/source_update.py b/tui_rsync/cli/source_update.py new file mode 100644 index 0000000..e1afa31 --- /dev/null +++ b/tui_rsync/cli/source_update.py @@ -0,0 +1,54 @@ +################################################################################ +# Copyright (C) 2023 Kostiantyn Klochko # +# # +# 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 . # +################################################################################ + +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) + diff --git a/tui_rsync/models/models.py b/tui_rsync/models/models.py index ad28d6c..c708799 100644 --- a/tui_rsync/models/models.py +++ b/tui_rsync/models/models.py @@ -37,6 +37,11 @@ class Path(BaseModel): class SyncCommand(BaseModel): command = CharField() + @staticmethod + def get_sync_command(args): + sync_cmd, _ = SyncCommand.get_or_create(command=args) + return sync_cmd + def __str__(self) -> str: return self.command @@ -45,6 +50,16 @@ class Source(BaseModel): source = ForeignKeyField(Path) 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 def create_save(label:str, source:str, destinations:list[str], args:str): src_path, _ = Path.get_or_create(path=source) @@ -61,6 +76,11 @@ class Source(BaseModel): src.save() return src + def update_args(self, args): + args_obj = SyncCommand.get_sync_command(args) + self.args = args_obj + self.save() + def __str__(self) -> str: return f"{self.label}"