2024-02-07 19:37:45 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import subprocess
|
2024-09-10 11:41:06 +02:00
|
|
|
from typing import Any, Optional
|
2024-02-07 19:37:45 +01:00
|
|
|
from functools import cache
|
|
|
|
from pathlib import Path
|
|
|
|
from git import Repo
|
|
|
|
|
|
|
|
import toml
|
|
|
|
|
|
|
|
REPO_APPS_ROOT = Path(Repo(__file__, search_parent_directories=True).working_dir)
|
|
|
|
|
|
|
|
|
2024-08-11 18:23:13 +02:00
|
|
|
def set_apps_path(apps_path: Path) -> None:
|
|
|
|
global REPO_APPS_ROOT
|
|
|
|
REPO_APPS_ROOT = apps_path
|
|
|
|
|
|
|
|
|
2024-02-09 01:41:33 +01:00
|
|
|
def git(cmd: list[str], cwd: Optional[Path] = None) -> str:
|
2024-02-07 19:37:45 +01:00
|
|
|
full_cmd = ["git"]
|
|
|
|
if cwd:
|
|
|
|
full_cmd.extend(["-C", str(cwd)])
|
|
|
|
full_cmd.extend(cmd)
|
2024-03-11 17:34:33 +01:00
|
|
|
return (
|
|
|
|
subprocess.check_output(
|
|
|
|
full_cmd,
|
|
|
|
# env=my_env,
|
|
|
|
)
|
|
|
|
.strip()
|
|
|
|
.decode("utf-8")
|
|
|
|
)
|
2024-02-07 19:37:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
@cache
|
2024-02-08 22:13:11 +01:00
|
|
|
def get_catalog(working_only: bool = False) -> dict[str, dict[str, Any]]:
|
2024-02-07 19:37:45 +01:00
|
|
|
"""Load the app catalog and filter out the non-working ones"""
|
|
|
|
catalog = toml.load((REPO_APPS_ROOT / "apps.toml").open("r", encoding="utf-8"))
|
|
|
|
if working_only:
|
|
|
|
catalog = {
|
2024-03-11 17:34:33 +01:00
|
|
|
app: infos
|
|
|
|
for app, infos in catalog.items()
|
2024-02-07 19:37:45 +01:00
|
|
|
if infos.get("state") != "notworking"
|
|
|
|
}
|
|
|
|
return catalog
|
2024-02-08 22:13:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
def get_categories() -> dict[str, Any]:
|
|
|
|
categories_path = REPO_APPS_ROOT / "categories.toml"
|
|
|
|
return toml.load(categories_path)
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
def get_antifeatures() -> dict[str, Any]:
|
|
|
|
antifeatures_path = REPO_APPS_ROOT / "antifeatures.toml"
|
|
|
|
return toml.load(antifeatures_path)
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
def get_wishlist() -> dict[str, dict[str, str]]:
|
|
|
|
wishlist_path = REPO_APPS_ROOT / "wishlist.toml"
|
|
|
|
return toml.load(wishlist_path)
|
|
|
|
|
|
|
|
|
|
|
|
@cache
|
|
|
|
def get_graveyard() -> dict[str, dict[str, str]]:
|
|
|
|
wishlist_path = REPO_APPS_ROOT / "graveyard.toml"
|
|
|
|
return toml.load(wishlist_path)
|