Migrate from Poetry and pyenv to uv
This commit is contained in:
@@ -6,7 +6,7 @@ leaving the tag name untouched. A timestamped backup of the index is written
|
||||
before saving.
|
||||
|
||||
Usage:
|
||||
poetry run python scripts/migrate_tag_category.py <pool_dir> \
|
||||
uv run python scripts/migrate_tag_category.py <pool_dir> \
|
||||
--old "Země" --new "Země původu"
|
||||
|
||||
If ``<pool_dir>`` is omitted, the pool from the global config is used.
|
||||
@@ -14,20 +14,20 @@ If ``<pool_dir>`` is omitted, the pool from the global config is used.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import shutil
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
# Allow running as a plain script (``python scripts/...``) by exposing the repo root.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from src.core.config import load_global_config # noqa: E402
|
||||
from src.core.pool_index import INDEX_FILENAME # noqa: E402
|
||||
from src.core.config import load_global_config
|
||||
from src.core.pool_index import INDEX_FILENAME
|
||||
|
||||
|
||||
def _rename_in_tags(tags: list[str], old: str, new: str) -> tuple[list[str], int]:
|
||||
@@ -37,7 +37,7 @@ def _rename_in_tags(tags: list[str], old: str, new: str) -> tuple[list[str], int
|
||||
result: list[str] = []
|
||||
for tag in tags:
|
||||
if isinstance(tag, str) and tag.startswith(prefix):
|
||||
result.append(f"{new}/{tag[len(prefix):]}")
|
||||
result.append(f"{new}/{tag[len(prefix) :]}")
|
||||
changed += 1
|
||||
else:
|
||||
result.append(tag)
|
||||
|
||||
@@ -7,27 +7,27 @@ Británie"``), de-duplicating within each record. A timestamped backup of the
|
||||
index is written before saving.
|
||||
|
||||
Usage:
|
||||
poetry run python scripts/split_country_tags.py [<pool_dir>] [--category "Země původu"]
|
||||
uv run python scripts/split_country_tags.py [<pool_dir>] [--category "Země původu"]
|
||||
|
||||
If ``<pool_dir>`` is omitted, the pool from the global config is used.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import shutil
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
# Allow running as a plain script (``python scripts/...``) by exposing the repo root.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from src.core.config import load_global_config # noqa: E402
|
||||
from src.core.pool_index import INDEX_FILENAME # noqa: E402
|
||||
from src.core.config import load_global_config
|
||||
from src.core.pool_index import INDEX_FILENAME
|
||||
|
||||
|
||||
def _split_record_tags(tags: list[str], category: str) -> tuple[list[str], int]:
|
||||
@@ -46,8 +46,12 @@ def _split_record_tags(tags: list[str], category: str) -> tuple[list[str], int]:
|
||||
result.append(tag)
|
||||
|
||||
for tag in tags:
|
||||
if isinstance(tag, str) and tag.startswith(prefix) and "/" in tag[len(prefix):]:
|
||||
value = tag[len(prefix):]
|
||||
if (
|
||||
isinstance(tag, str)
|
||||
and tag.startswith(prefix)
|
||||
and "/" in tag[len(prefix) :]
|
||||
):
|
||||
value = tag[len(prefix) :]
|
||||
countries = [c.strip() for c in value.split("/") if c.strip()]
|
||||
for country in countries:
|
||||
_add(f"{prefix}{country}")
|
||||
|
||||
@@ -7,26 +7,26 @@ This removes the legacy band tags (``Hodnocení/<x>–<y> %``) so re-fetching fr
|
||||
backup of the index is written first.
|
||||
|
||||
Usage:
|
||||
poetry run python scripts/strip_rating_bands.py [<pool_dir>] [--category "Hodnocení"]
|
||||
uv run python scripts/strip_rating_bands.py [<pool_dir>] [--category "Hodnocení"]
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
import shutil
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
# Allow running as a plain script (``python scripts/...``) by exposing the repo root.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from src.core.config import load_global_config # noqa: E402
|
||||
from src.core.pool_index import INDEX_FILENAME # noqa: E402
|
||||
from src.core.config import load_global_config
|
||||
from src.core.pool_index import INDEX_FILENAME
|
||||
|
||||
# A band tag looks like "Hodnocení/90–100 %" — value has a dash range and a "%".
|
||||
_BAND_RE = re.compile(r"\d+\s*[–-]\s*\d+\s*%")
|
||||
@@ -36,7 +36,8 @@ def _strip_bands(tags: list[str], category: str) -> tuple[list[str], int]:
|
||||
"""Return (kept tags, removed count), dropping ``category`` band tags."""
|
||||
prefix = f"{category}/"
|
||||
kept = [
|
||||
t for t in tags
|
||||
t
|
||||
for t in tags
|
||||
if not (isinstance(t, str) and t.startswith(prefix) and _BAND_RE.search(t))
|
||||
]
|
||||
return kept, len(tags) - len(kept)
|
||||
@@ -58,7 +59,8 @@ def migrate(index_path: Path, category: str) -> int:
|
||||
# also drop them from the ČSFD provenance set, if present
|
||||
if isinstance(record.get("csfd_tags"), list):
|
||||
record["csfd_tags"] = [
|
||||
t for t in record["csfd_tags"]
|
||||
t
|
||||
for t in record["csfd_tags"]
|
||||
if not (t.startswith(f"{category}/") and _BAND_RE.search(t))
|
||||
]
|
||||
total_removed += removed
|
||||
|
||||
@@ -5,26 +5,26 @@ Herec produced far too many folders). Cached ČSFD data is left intact — only
|
||||
``tags`` lists are pruned. A timestamped backup of the index is written first.
|
||||
|
||||
Usage:
|
||||
poetry run python scripts/strip_tag_categories.py [<pool_dir>] \
|
||||
uv run python scripts/strip_tag_categories.py [<pool_dir>] \
|
||||
--categories "Režie" "Herec"
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
import json
|
||||
import shutil
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
# Allow running as a plain script (``python scripts/...``) by exposing the repo root.
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from src.core.config import load_global_config # noqa: E402
|
||||
from src.core.pool_index import INDEX_FILENAME # noqa: E402
|
||||
from src.core.config import load_global_config
|
||||
from src.core.pool_index import INDEX_FILENAME
|
||||
|
||||
|
||||
def _strip(tags: list[str], prefixes: tuple[str, ...]) -> tuple[list[str], int]:
|
||||
|
||||
Regular → Executable
+26
-13
@@ -16,11 +16,11 @@ Examples:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import random
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
INDEX_FILENAME = ".Curator.!index"
|
||||
@@ -34,7 +34,7 @@ def _load_config_paths(config_path: Path) -> tuple[Path | None, Path | None]:
|
||||
try:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
cfg = json.load(f)
|
||||
except (OSError, json.JSONDecodeError):
|
||||
except OSError, json.JSONDecodeError:
|
||||
return None, None
|
||||
pool = cfg.get("pool_dir")
|
||||
out = cfg.get("filmoteka_dir")
|
||||
@@ -99,20 +99,33 @@ def generate_tips(pool_dir: Path, output_dir: Path, count: int, subfolder: str)
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Vygeneruje složku Tipy dne.")
|
||||
parser.add_argument("--pool", type=Path, help="Pool root (obsahuje .Curator.!index)")
|
||||
parser.add_argument(
|
||||
"--pool", type=Path, help="Pool root (obsahuje .Curator.!index)"
|
||||
)
|
||||
parser.add_argument("--output", type=Path, help="Výstupní složka Filmotéky")
|
||||
parser.add_argument("--count", type=int, default=DEFAULT_COUNT,
|
||||
help=f"Počet náhodných titulů (výchozí {DEFAULT_COUNT})")
|
||||
parser.add_argument("--subfolder", default=DEFAULT_SUBFOLDER,
|
||||
help=f'Název složky tipů (výchozí "{DEFAULT_SUBFOLDER}")')
|
||||
parser.add_argument("--config", type=Path,
|
||||
help="Cesta ke global configu (.Curator.!gtag) pro doplnění cest")
|
||||
parser.add_argument(
|
||||
"--count",
|
||||
type=int,
|
||||
default=DEFAULT_COUNT,
|
||||
help=f"Počet náhodných titulů (výchozí {DEFAULT_COUNT})",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--subfolder",
|
||||
default=DEFAULT_SUBFOLDER,
|
||||
help=f'Název složky tipů (výchozí "{DEFAULT_SUBFOLDER}")',
|
||||
)
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
type=Path,
|
||||
help="Cesta ke global configu (.Curator.!gtag) pro doplnění cest",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
pool, output = args.pool, args.output
|
||||
if pool is None or output is None:
|
||||
config_path = args.config or (
|
||||
Path(__file__).resolve().parent.parent / GLOBAL_CONFIG_FILENAME)
|
||||
Path(__file__).resolve().parent.parent / GLOBAL_CONFIG_FILENAME
|
||||
)
|
||||
cfg_pool, cfg_out = _load_config_paths(config_path)
|
||||
pool = pool or cfg_pool
|
||||
output = output or cfg_out
|
||||
|
||||
Reference in New Issue
Block a user