Commonize code to read catalog, categories etc
This commit is contained in:
parent
370c4445c5
commit
a286aa3c61
3 changed files with 53 additions and 72 deletions
|
@ -61,7 +61,7 @@ def progressbar(
|
||||||
|
|
||||||
|
|
||||||
@cache
|
@cache
|
||||||
def get_catalog(working_only=False):
|
def get_catalog(working_only: bool = False) -> dict[str, dict[str, Any]]:
|
||||||
"""Load the app catalog and filter out the non-working ones"""
|
"""Load the app catalog and filter out the non-working ones"""
|
||||||
catalog = toml.load((REPO_APPS_ROOT / "apps.toml").open("r", encoding="utf-8"))
|
catalog = toml.load((REPO_APPS_ROOT / "apps.toml").open("r", encoding="utf-8"))
|
||||||
if working_only:
|
if working_only:
|
||||||
|
@ -70,3 +70,28 @@ def get_catalog(working_only=False):
|
||||||
if infos.get("state") != "notworking"
|
if infos.get("state") != "notworking"
|
||||||
}
|
}
|
||||||
return catalog
|
return catalog
|
||||||
|
|
||||||
|
|
||||||
|
@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)
|
||||||
|
|
||||||
|
|
|
@ -3,48 +3,16 @@
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from functools import cache
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, Generator, List, Tuple
|
from typing import Any, Dict, Generator, List, Tuple
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
import toml
|
from appslib.utils import (REPO_APPS_ROOT, # pylint: disable=import-error
|
||||||
|
get_antifeatures, get_catalog, get_categories,
|
||||||
APPS_ROOT = Path(__file__).parent.parent
|
get_graveyard, get_wishlist)
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def get_catalog() -> Dict[str, Dict[str, Any]]:
|
|
||||||
catalog_path = APPS_ROOT / "apps.toml"
|
|
||||||
return toml.load(catalog_path)
|
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def get_categories() -> Dict[str, Any]:
|
|
||||||
categories_path = APPS_ROOT / "categories.toml"
|
|
||||||
return toml.load(categories_path)
|
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def get_antifeatures() -> Dict[str, Any]:
|
|
||||||
antifeatures_path = APPS_ROOT / "antifeatures.toml"
|
|
||||||
return toml.load(antifeatures_path)
|
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def get_wishlist() -> Dict[str, Dict[str, str]]:
|
|
||||||
wishlist_path = APPS_ROOT / "wishlist.toml"
|
|
||||||
return toml.load(wishlist_path)
|
|
||||||
|
|
||||||
|
|
||||||
@cache
|
|
||||||
def get_graveyard() -> Dict[str, Dict[str, str]]:
|
|
||||||
wishlist_path = APPS_ROOT / "graveyard.toml"
|
|
||||||
return toml.load(wishlist_path)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_schema() -> Generator[str, None, None]:
|
def validate_schema() -> Generator[str, None, None]:
|
||||||
with open(APPS_ROOT / "schemas" / "apps.toml.schema.json", encoding="utf-8") as file:
|
with open(REPO_APPS_ROOT / "schemas" / "apps.toml.schema.json", encoding="utf-8") as file:
|
||||||
apps_catalog_schema = json.load(file)
|
apps_catalog_schema = json.load(file)
|
||||||
validator = jsonschema.Draft202012Validator(apps_catalog_schema)
|
validator = jsonschema.Draft202012Validator(apps_catalog_schema)
|
||||||
for error in validator.iter_errors(get_catalog()):
|
for error in validator.iter_errors(get_catalog()):
|
||||||
|
|
|
@ -20,41 +20,29 @@ from packaging_v2.convert_v1_manifest_to_v2_for_catalog import \
|
||||||
convert_v1_manifest_to_v2_for_catalog # pylint: disable=import-error
|
convert_v1_manifest_to_v2_for_catalog # pylint: disable=import-error
|
||||||
|
|
||||||
from appslib.utils import (REPO_APPS_ROOT, # pylint: disable=import-error
|
from appslib.utils import (REPO_APPS_ROOT, # pylint: disable=import-error
|
||||||
get_catalog, git_repo_age)
|
get_antifeatures, get_catalog, get_categories)
|
||||||
|
|
||||||
# Automatically enables error-to-xmpp
|
|
||||||
import appslib.xmpplogger # pylint: disable=import-error
|
|
||||||
|
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
|
||||||
|
|
||||||
# Load categories and reformat the structure to have a list with an "id" key
|
@cache
|
||||||
categories = toml.load((REPO_APPS_ROOT / "categories.toml").open("r", encoding="utf-8"))
|
def categories_list():
|
||||||
for category_id, infos in categories.items():
|
# Load categories and reformat the structure to have a list with an "id" key
|
||||||
infos["id"] = category_id
|
new_categories = get_categories()
|
||||||
for subtag_id, subtag_infos in infos.get("subtags", {}).items():
|
for category_id, infos in new_categories.items():
|
||||||
subtag_infos["id"] = subtag_id
|
infos["id"] = category_id
|
||||||
infos["subtags"] = list(infos.get('subtags', {}).values())
|
for subtag_id, subtag_infos in infos.get("subtags", {}).items():
|
||||||
|
subtag_infos["id"] = subtag_id
|
||||||
|
infos["subtags"] = list(infos.get('subtags', {}).values())
|
||||||
|
return list(new_categories.values())
|
||||||
|
|
||||||
categories = list(categories.values())
|
|
||||||
|
|
||||||
# (Same for antifeatures)
|
@cache
|
||||||
antifeatures = toml.load((REPO_APPS_ROOT / "antifeatures.toml").open("r", encoding="utf-8"))
|
def antifeatures_list():
|
||||||
for antifeature_id, infos in antifeatures.items():
|
# (Same for antifeatures)
|
||||||
infos["id"] = antifeature_id
|
new_antifeatures = get_antifeatures()
|
||||||
antifeatures = list(antifeatures.values())
|
for antifeature_id, infos in new_antifeatures.items():
|
||||||
|
infos["id"] = antifeature_id
|
||||||
# Load the app catalog and filter out the non-working ones
|
return list(new_antifeatures.values())
|
||||||
catalog = toml.load((REPO_APPS_ROOT / "apps.toml").open("r", encoding="utf-8"))
|
|
||||||
catalog = {
|
|
||||||
app: infos for app, infos in catalog.items() if infos.get("state") != "notworking"
|
|
||||||
}
|
|
||||||
|
|
||||||
my_env = os.environ.copy()
|
|
||||||
my_env["GIT_TERMINAL_PROMPT"] = "0"
|
|
||||||
|
|
||||||
(REPO_APPS_ROOT / "builds").mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
|
|
||||||
################################
|
################################
|
||||||
|
@ -92,8 +80,8 @@ def write_catalog_v2(base_catalog, target_dir: Path) -> None:
|
||||||
}
|
}
|
||||||
full_catalog = {
|
full_catalog = {
|
||||||
"apps": result_dict_with_manifest_v1,
|
"apps": result_dict_with_manifest_v1,
|
||||||
"categories": categories,
|
"categories": categories_list(),
|
||||||
"antifeatures": antifeatures,
|
"antifeatures": antifeatures_list(),
|
||||||
}
|
}
|
||||||
|
|
||||||
target_file = target_dir / "apps.json"
|
target_file = target_dir / "apps.json"
|
||||||
|
@ -130,8 +118,8 @@ def write_catalog_v3(base_catalog, target_dir: Path) -> None:
|
||||||
|
|
||||||
full_catalog = {
|
full_catalog = {
|
||||||
"apps": result_dict_with_manifest_v2,
|
"apps": result_dict_with_manifest_v2,
|
||||||
"categories": categories,
|
"categories": categories_list(),
|
||||||
"antifeatures": antifeatures,
|
"antifeatures": antifeatures_list(),
|
||||||
}
|
}
|
||||||
|
|
||||||
target_file = target_dir / "apps.json"
|
target_file = target_dir / "apps.json"
|
||||||
|
@ -166,7 +154,7 @@ def write_catalog_doc(base_catalog, target_dir: Path) -> None:
|
||||||
}
|
}
|
||||||
full_catalog = {
|
full_catalog = {
|
||||||
"apps": result_dict_doc,
|
"apps": result_dict_doc,
|
||||||
"categories": categories
|
"categories": categories_list()
|
||||||
}
|
}
|
||||||
|
|
||||||
target_file = target_dir / "apps.json"
|
target_file = target_dir / "apps.json"
|
||||||
|
|
Loading…
Reference in a new issue