appstore: black app.py and utils.py
This commit is contained in:
@ -9,22 +9,23 @@ from flask import request
|
||||
|
||||
|
||||
AVAILABLE_LANGUAGES = ["en"] + os.listdir("translations")
|
||||
|
||||
|
||||
def get_locale():
|
||||
# try to guess the language from the user accept
|
||||
# The best match wins.
|
||||
return request.accept_languages.best_match(AVAILABLE_LANGUAGES)
|
||||
|
||||
def get_catalog():
|
||||
|
||||
def get_catalog():
|
||||
path = "../builds/default/v3/apps.json"
|
||||
mtime = os.path.getmtime(path)
|
||||
if get_catalog.mtime_catalog != mtime:
|
||||
|
||||
get_catalog.mtime_catalog = mtime
|
||||
|
||||
catalog = json.load(open(path))
|
||||
catalog['categories'] = {c['id']:c for c in catalog['categories']}
|
||||
catalog['antifeatures'] = {c['id']:c for c in catalog['antifeatures']}
|
||||
catalog["categories"] = {c["id"]: c for c in catalog["categories"]}
|
||||
catalog["antifeatures"] = {c["id"]: c for c in catalog["antifeatures"]}
|
||||
|
||||
category_color = {
|
||||
"synchronization": "sky",
|
||||
@ -43,35 +44,38 @@ def get_catalog():
|
||||
"wat": "teal",
|
||||
}
|
||||
|
||||
for id_, category in catalog['categories'].items():
|
||||
for id_, category in catalog["categories"].items():
|
||||
category["color"] = category_color[id_]
|
||||
|
||||
get_catalog.cache_catalog = catalog
|
||||
|
||||
return get_catalog.cache_catalog
|
||||
|
||||
|
||||
get_catalog.mtime_catalog = None
|
||||
get_catalog()
|
||||
|
||||
|
||||
def get_wishlist():
|
||||
|
||||
path = "../wishlist.toml"
|
||||
mtime = os.path.getmtime(path)
|
||||
if get_wishlist.mtime_wishlist != mtime:
|
||||
|
||||
get_wishlist.mtime_wishlist = mtime
|
||||
get_wishlist.cache_wishlist = toml.load(open(path))
|
||||
|
||||
return get_wishlist.cache_wishlist
|
||||
|
||||
|
||||
get_wishlist.mtime_wishlist = None
|
||||
get_wishlist()
|
||||
|
||||
|
||||
def get_stars():
|
||||
|
||||
checksum = subprocess.check_output("find . -type f -printf '%T@,' | md5sum", shell=True).decode().split()[0]
|
||||
checksum = (
|
||||
subprocess.check_output("find . -type f -printf '%T@,' | md5sum", shell=True)
|
||||
.decode()
|
||||
.split()[0]
|
||||
)
|
||||
if get_stars.cache_checksum != checksum:
|
||||
stars = {}
|
||||
for folder, _, files in os.walk(".stars/"):
|
||||
@ -84,6 +88,7 @@ def get_stars():
|
||||
|
||||
return get_stars.cache_stars
|
||||
|
||||
|
||||
get_stars.cache_checksum = None
|
||||
get_stars()
|
||||
|
||||
@ -98,9 +103,7 @@ def human_to_binary(size: str) -> int:
|
||||
size = size[:-1]
|
||||
|
||||
if suffix not in symbols:
|
||||
raise Exception(
|
||||
f"Invalid size suffix '{suffix}', expected one of {symbols}"
|
||||
)
|
||||
raise Exception(f"Invalid size suffix '{suffix}', expected one of {symbols}")
|
||||
|
||||
try:
|
||||
size_ = float(size)
|
||||
@ -111,10 +114,11 @@ def human_to_binary(size: str) -> int:
|
||||
|
||||
|
||||
def get_app_md_and_screenshots(app_folder, infos):
|
||||
|
||||
locale = get_locale()
|
||||
|
||||
if locale != "en" and os.path.exists(os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md")):
|
||||
if locale != "en" and os.path.exists(
|
||||
os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md")
|
||||
):
|
||||
description_path = os.path.join(app_folder, "doc", f"DESCRIPTION_{locale}.md")
|
||||
elif os.path.exists(os.path.join(app_folder, "doc", "DESCRIPTION.md")):
|
||||
description_path = os.path.join(app_folder, "doc", "DESCRIPTION.md")
|
||||
@ -122,11 +126,15 @@ def get_app_md_and_screenshots(app_folder, infos):
|
||||
description_path = None
|
||||
if description_path:
|
||||
with open(description_path) as f:
|
||||
infos["full_description_html"] = emojize(pycmarkgfm.gfm_to_html(f.read()), language="alias")
|
||||
infos["full_description_html"] = emojize(
|
||||
pycmarkgfm.gfm_to_html(f.read()), language="alias"
|
||||
)
|
||||
else:
|
||||
infos["full_description_html"] = infos['manifest']['description'][locale]
|
||||
infos["full_description_html"] = infos["manifest"]["description"][locale]
|
||||
|
||||
if locale != "en" and os.path.exists(os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md")):
|
||||
if locale != "en" and os.path.exists(
|
||||
os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md")
|
||||
):
|
||||
pre_install_path = os.path.join(app_folder, "doc", f"PRE_INSTALL_{locale}.md")
|
||||
elif os.path.exists(os.path.join(app_folder, "doc", "PRE_INSTALL.md")):
|
||||
pre_install_path = os.path.join(app_folder, "doc", "PRE_INSTALL.md")
|
||||
@ -134,7 +142,9 @@ def get_app_md_and_screenshots(app_folder, infos):
|
||||
pre_install_path = None
|
||||
if pre_install_path:
|
||||
with open(pre_install_path) as f:
|
||||
infos["pre_install_html"] = emojize(pycmarkgfm.gfm_to_html(f.read()), language="alias")
|
||||
infos["pre_install_html"] = emojize(
|
||||
pycmarkgfm.gfm_to_html(f.read()), language="alias"
|
||||
)
|
||||
|
||||
infos["screenshot"] = None
|
||||
|
||||
@ -153,4 +163,6 @@ def get_app_md_and_screenshots(app_folder, infos):
|
||||
break
|
||||
|
||||
ram_build_requirement = infos["manifest"]["integration"]["ram"]["build"]
|
||||
infos["manifest"]["integration"]["ram"]["build_binary"] = human_to_binary(ram_build_requirement)
|
||||
infos["manifest"]["integration"]["ram"]["build_binary"] = human_to_binary(
|
||||
ram_build_requirement
|
||||
)
|
||||
|
Reference in New Issue
Block a user