Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions projects/butter-backup/src/butter_backup/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import os
import sys
import typing as t
from collections.abc import Callable
from pathlib import Path
from tempfile import mkdtemp
from typing import Any, Callable
from typing import Any

import shell_interface as sh
import storage_device_managers as sdm
Expand Down Expand Up @@ -133,8 +134,8 @@ def _skip_device(
return False


CONFIG_OPTION = typer.Option(None, exists=True, dir_okay=False)
VERBOSITY_OPTION = typer.Option(0, "--verbose", "-v", count=True)
CONFIG_OPTION = typer.Option(exists=True, dir_okay=False)
VERBOSITY_OPTION = typer.Option("--verbose", "-v", count=True)


def _open_device(
Expand All @@ -161,9 +162,9 @@ def _open_device(

@app.command()
def open( # noqa: A001
dest: Path | None = typer.Argument(None), # noqa: B008
config: Path | None = CONFIG_OPTION,
verbose: int = VERBOSITY_OPTION,
dest: t.Annotated[Path | None, typer.Argument()] = None,
config: t.Annotated[Path | None, CONFIG_OPTION] = None,
verbose: t.Annotated[int, VERBOSITY_OPTION] = 0,
) -> None:
"""
Öffne alle in der Konfiguration gelisteten Speichermedien
Expand Down Expand Up @@ -198,7 +199,10 @@ def open( # noqa: A001


@app.command()
def close(config: Path | None = CONFIG_OPTION, verbose: int = VERBOSITY_OPTION) -> None:
def close(
config: t.Annotated[Path | None, CONFIG_OPTION] = None,
verbose: t.Annotated[int, VERBOSITY_OPTION] = 0,
) -> None:
"""
Schließe alle geöffneten Speichermedien

Expand Down Expand Up @@ -230,7 +234,8 @@ def close(config: Path | None = CONFIG_OPTION, verbose: int = VERBOSITY_OPTION)

@app.command()
def backup(
config: Path | None = CONFIG_OPTION, verbose: int = VERBOSITY_OPTION
config: t.Annotated[Path | None, CONFIG_OPTION] = None,
verbose: t.Annotated[int, VERBOSITY_OPTION] = 0,
) -> None:
"""
Führe Sicherheitskopien durch
Expand Down Expand Up @@ -278,23 +283,27 @@ def backup(

@app.command()
def format_device(
backend: ValidBackends = typer.Argument(...), # noqa: B008
device: Path = typer.Argument( # noqa: B008
..., exists=True, dir_okay=False, readable=False
),
file_system: ValidFileSystems | None = typer.Option( # noqa: B008
None,
"--file-system",
help="Dateisystem für das Restic-Backend. Andere Werte als `btrfs` nur für das"
"Restic-Backend gültig. Unterstützte Dateisysteme: btrfs, ext4.",
),
config_to: Path | None = typer.Option( # noqa: B008
None,
help="Datei, in welche die generierte Konfiguration geschrieben werden"
" soll. Die angegebene Datei darf nicht existieren. Wenn nicht"
" angegeben, wird die Konfiguration auf STDOUT ausgegeben.",
),
verbose: int = VERBOSITY_OPTION,
backend: t.Annotated[ValidBackends, typer.Argument()],
device: t.Annotated[
Path, typer.Argument(exists=True, dir_okay=False, readable=False)
],
file_system: t.Annotated[
ValidFileSystems | None,
typer.Option(
"--file-system",
help="Dateisystem für das Restic-Backend. Andere Werte als `btrfs` nur für das"
"Restic-Backend gültig. Unterstützte Dateisysteme: btrfs, ext4.",
),
] = None,
config_to: t.Annotated[
Path | None,
typer.Option(
help="Datei, in welche die generierte Konfiguration geschrieben werden"
" soll. Die angegebene Datei darf nicht existieren. Wenn nicht"
" angegeben, wird die Konfiguration auf STDOUT ausgegeben.",
),
] = None,
verbose: t.Annotated[int, VERBOSITY_OPTION] = 0,
) -> None:
"""
Richtet Speichermedium für butter-backup ein
Expand Down
3 changes: 2 additions & 1 deletion projects/butter-backup/tests/test_backup_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import os
import typing as t
from collections import Counter
from collections.abc import Iterable
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Iterable, overload
from typing import overload
from uuid import uuid4

import pytest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import subprocess
from pathlib import Path
from types import SimpleNamespace
from typing import List, Optional, Union

try:
from loguru import logger # type: ignore[import, unused-ignore]
Expand All @@ -16,8 +15,8 @@
logger.debug = lambda msg: None # type: ignore[assignment, unused-ignore]
logger.error = lambda msg: None # type: ignore[assignment, unused-ignore]

StrPathList = List[Union[str, Path]]
_CMD_LIST = Union[List[str], List[Path], StrPathList]
StrPathList = list[str | Path]
_CMD_LIST = list[str] | list[Path] | StrPathList


class PassCmdError(RuntimeError):
Expand All @@ -31,7 +30,7 @@ class ShellInterfaceError(RuntimeError):
def run_cmd(
*,
cmd: _CMD_LIST,
env: Optional[dict[str, str]] = None,
env: dict[str, str] | None = None,
capture_output: bool = False,
) -> subprocess.CompletedProcess[bytes]:
"""
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ select = [
"C",
"E",
"F",
"FURB",
"I",
"ISC",
"PIE",
Expand All @@ -49,6 +50,7 @@ select = [
"RUF",
"SIM",
"TID",
"UP",
"W",
"YTT",
]
Expand Down
Loading