37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import json
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
|
|
def normalized_path(path: str) -> str:
|
|
return path.replace("\\", "/").casefold()
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class PatchLayout:
|
|
repository_patches: frozenset[str]
|
|
graphics_patches: frozenset[str]
|
|
|
|
def is_repository_patch(self, path: str) -> bool:
|
|
return normalized_path(path) in self.repository_patches
|
|
|
|
def is_graphics_patch(self, path: str) -> bool:
|
|
return normalized_path(path) in self.graphics_patches
|
|
|
|
def is_external_graphics_patch(self, path: str) -> bool:
|
|
key = normalized_path(path)
|
|
return key in self.graphics_patches and key not in self.repository_patches
|
|
|
|
|
|
def load_patch_layout(path: Path | None = None) -> PatchLayout:
|
|
config_path = path or Path(__file__).resolve().with_name("patch-layout.json")
|
|
data = json.loads(config_path.read_text(encoding="utf-8"))
|
|
repository = frozenset(normalized_path(item) for item in data["repositoryPatches"])
|
|
graphics = frozenset(normalized_path(item) for item in data["graphicsPatches"])
|
|
return PatchLayout(repository_patches=repository, graphics_patches=graphics)
|
|
|
|
|
|
PATCH_LAYOUT = load_patch_layout()
|