From 352aeac1464eb12729c779bc93a10862162deed3 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 1 Sep 2023 21:57:21 +0200 Subject: [PATCH] appstore: display unusual ram requirement, arch limitation, pre-install notes, emojis --- store/app.py | 30 ++++++++++++++++++++++++++++-- store/requirements.txt | 1 + store/templates/app.html | 23 +++++++++++++++++++---- store/templates/base.html | 3 +++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/store/app.py b/store/app.py index 364a9d1b..e5b22107 100644 --- a/store/app.py +++ b/store/app.py @@ -13,6 +13,7 @@ import sys from slugify import slugify from flask import Flask, send_from_directory, render_template, session, redirect, request from github import Github, InputGitAuthor +from emoji import emojize locale = "en" app = Flask(__name__, static_url_path='/assets', static_folder="assets") @@ -72,6 +73,28 @@ wishlist = toml.load(open("../wishlist.toml")) app.secret_key = ''.join([str(random.randint(0, 9)) for i in range(99)]) +def human_to_binary(size: str) -> int: + symbols = ("K", "M", "G", "T", "P", "E", "Z", "Y") + factor = {} + for i, s in enumerate(symbols): + factor[s] = 1 << (i + 1) * 10 + + suffix = size[-1] + size = size[:-1] + + if suffix not in symbols: + raise YunohostError( + f"Invalid size suffix '{suffix}', expected one of {symbols}" + ) + + try: + size_ = float(size) + except Exception: + raise YunohostError(f"Failed to convert size {size} to float") + + return int(size_ * factor[suffix]) + + @app.route('/favicon.ico') def favicon(): return send_from_directory('assets', 'favicon.png') @@ -138,7 +161,7 @@ def app_info(app_id): description_path = None if description_path: with open(description_path) as f: - infos["full_description_html"] = pycmarkgfm.gfm_to_html(f.read()) + infos["full_description_html"] = emojize(pycmarkgfm.gfm_to_html(f.read()), language="alias") else: infos["full_description_html"] = infos['manifest']['description'][locale] @@ -150,7 +173,7 @@ def app_info(app_id): pre_install_path = None if pre_install_path: with open(pre_install_path) as f: - infos["pre_install_html"] = pycmarkgfm.gfm_to_html(f.read()) + infos["pre_install_html"] = emojize(pycmarkgfm.gfm_to_html(f.read()), language="alias") infos["screenshot"] = None @@ -168,6 +191,9 @@ def app_info(app_id): ] = f"data:image/{ext};charset=utf-8;base64,{data}" break + ram_build_requirement = infos["manifest"]["integration"]["ram"]["build"] + infos["manifest"]["integration"]["ram"]["build_binary"] = human_to_binary(ram_build_requirement) + return render_template("app.html", user=session.get('user', {}), app_id=app_id, infos=infos, catalog=catalog) diff --git a/store/requirements.txt b/store/requirements.txt index a982909d..996af51b 100644 --- a/store/requirements.txt +++ b/store/requirements.txt @@ -4,3 +4,4 @@ PyGithub toml pycmarkgfm gunicorn +emoji diff --git a/store/templates/app.html b/store/templates/app.html index 78be075f..a6c54203 100644 --- a/store/templates/app.html +++ b/store/templates/app.html @@ -62,16 +62,31 @@
{{ infos["full_description_html"]|safe }}
{% if infos["screenshot"] %} - + {% endif %} + {% if infos["manifest"]["integration"]["architectures"] != "all" %} +
+ This app is only compatible with these specific architectures : {{ infos["manifest"]["integration"]["architectures"]|join(', ') }} +
+ {% endif %} -

{{ infos["manifest"]["integration"] }}

-
{{ infos["pre_install_html"] | safe }}
+ {% if infos["manifest"]["integration"]["ram"]["build_binary"] >= 500 * 1024 * 1024 %} +
+ This app requires an unusual amount of RAM to build : {{ infos["manifest"]["integration"]["ram"]["build"] }} +
+ {% endif %} + + {% if infos["pre_install_html"] %} +
+

Important infos before installing

+
{{ infos["pre_install_html"] | safe }}
+
+ {% endif %} {% if infos["antifeatures"] %}

Anti-features

(This app has features you may not like)

-
+
    {% for antifeature in infos["antifeatures"] %}
  • {{ catalog['antifeatures'][antifeature]['description'][locale] }}
  • diff --git a/store/templates/base.html b/store/templates/base.html index 20ed7725..1f643e86 100644 --- a/store/templates/base.html +++ b/store/templates/base.html @@ -40,6 +40,9 @@ padding: revert; list-style: disc; } + .from-markdown a { + @apply text-blue-600; + } }