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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ Defaults to `28`.

The maximum Hamming distance accepted when matching an archive cover.

Defaults to `10`. Supported values range from `0` to `64`.
Defaults to `10`. Supported values range from `0` to `20`.

## Socials

Expand Down
5 changes: 4 additions & 1 deletion perdoo/cli/convert/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def convert_comic_images(
continue
comic.write_file(filename=new_name, data=data)
comic.remove_file(filename=name)
CONSOLE.print(f"Converted {name!r} to {new_name!r}")
CONSOLE.print(
f"Converted '{comic.file.name}!/{name}' to '{comic.file.name}!/{new_name}'",
style="logging.level.info",
)
existing.add(new_name)
changed += 1
if failed:
Expand Down
5 changes: 4 additions & 1 deletion perdoo/cli/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def rename_comic(comic: Comic, image_exts: Sequence[str]) -> bool:
new_name = f"{str(idx).zfill(pad)}{standardize_image_suffix(suffix)}"
idx += 1
if filename != new_name:
CONSOLE.print(f"Renaming {filename!r} to {new_name!r}")
CONSOLE.print(
f"Renaming '{comic.file.name}!/{filename}' to '{comic.file.name}!/{new_name}''", # noqa: E501
style="logging.level.info",
)
comic.rename_file(filename=filename, new_name=new_name, override=True)
renamed = True
except ArchiveCapabilityError as err:
Expand Down
21 changes: 12 additions & 9 deletions perdoo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from enum import StrEnum
from pathlib import Path
from typing import Annotated, ClassVar, Literal, Self, get_args
from typing import Annotated, Literal, Self, get_args

from msgspec import Meta, Struct, ValidationError, convert, field, structs, to_builtins
from msgspec.toml import decode, encode
Expand Down Expand Up @@ -61,39 +61,42 @@ class Services(Struct, rename="kebab"):

class Sync(Struct, rename="kebab"):
cover_hash_distance: Annotated[
int, Meta(ge=0, le=64, description="'cover-hash-distance' must be between 0 and 64")
int, Meta(ge=0, le=20, description="'cover-hash-distance' must be between 0 and 20")
] = 10
days: Annotated[int, Meta(ge=7, description="'days' must be greater than 6")] = 28


class Settings(Struct, rename="kebab"):
_file: ClassVar[Path] = get_config_home() / "settings.toml"

output: Output = field(default_factory=Output)
removals: list[str] = field(
default_factory=lambda: ["*.db", "*.ini", "*.nfo", "*.sfv", ".DS_Store"]
)
services: Services = field(default_factory=Services)
sync: Sync = field(default_factory=Sync)

@classmethod
def _file(cls) -> Path:
return get_config_home() / "settings.toml"

@property
def path(self) -> Path:
return self._file
return self._file()

@classmethod
def load(cls) -> "Settings":
if not cls._file.exists():
file = cls._file()
if not file.exists():
return cls().save()
try:
return convert(
_restore_none(value=decode(cls._file.read_bytes()), struct_type=cls),
_restore_none(value=decode(file.read_bytes()), struct_type=cls),
type=cls,
dec_hook=lambda typ, obj: (
Path(obj) if typ is Path and isinstance(obj, str) else obj
),
)
except ValidationError as err:
raise ValueError(f"Invalid settings file {cls._file}: {err}") from err
raise ValueError(f"Invalid settings file {file}: {err}") from err

def save(self) -> Self:
def encoder(obj: object) -> object:
Expand Down Expand Up @@ -123,7 +126,7 @@ def encoder(obj: object) -> object:
]

CONSOLE.print(Panel.fit("\n".join(default_vals), title="Default Settings"))
CONSOLE.print(Panel.fit("\n".join(override_vals), title=str(cls._file)))
CONSOLE.print(Panel.fit("\n".join(override_vals), title=str(cls._file())))


def _toml_serializable(value: object) -> object:
Expand Down
Loading