diff --git a/app.py b/app.py index 98524bb..0a63e8f 100644 --- a/app.py +++ b/app.py @@ -45,15 +45,22 @@ def before_request(): @app.context_processor def _inject_autobuild_vers(): - return {"autobuild_vers": autobuild.autobuild_vers} + return { + "autobuild_vers": autobuild.autobuild_vers, + "autobuild_sizes": autobuild.autobuild_sizes, + } @app.context_processor def _inject_autobuild_date(): return { - "autobuild_date": g.translations.get("downloads", {}) - .get("date-format", "{DD}.{MM}.{YYYY}") - .format(**autobuild.autobuild_date) + "autobuild_date": autobuild.autobuild_date.strftime( + g.translations.get("downloads", {}) + .get("date-format", "{DD}.{MM}.{YYYY}") + .replace("{YYYY}", "%Y") + .replace("{MM}", "%m") + .replace("{DD}", "%d") + ) } diff --git a/modules/autobuild.py b/modules/autobuild.py index 068f849..3de8ac8 100644 --- a/modules/autobuild.py +++ b/modules/autobuild.py @@ -1,22 +1,50 @@ +from datetime import date import re import threading import time +from urllib.request import Request, urlopen + STATUS_URL = "http://builds.kolibrios.org/status.html" STATUS_SEC = 300 # refetch each 5 minutes +DOWNLOAD_LANGS = ("en_US", "ru_RU", "es_ES") +DOWNLOAD_EXTS = ("img", "iso", "distr", "raw") -autobuild_date = {"YYYY": "YYYY", "MM": "MM", "DD": "DD"} +VER_RE = re.compile(r"\b(\d+\.\d+\.\d+\.\d+\+\d{3,8}-[0-9a-fA-F]{7,40})\b") +DATE_RE = re.compile(r"\b(\d{4})\.(\d{2})\.(\d{2})\s+\d{2}:\d{2}:\d{2}\b") +ROW_RE = re.compile(r"(]*>.*?)", flags=re.I | re.S) + +autobuild_date = date.today() autobuild_vers = "0.0.0.0+0000-0000000" +autobuild_sizes = { + lang: {ext: "?" for ext in DOWNLOAD_EXTS} + for lang in DOWNLOAD_LANGS +} _started = False _updater_lock = threading.Lock() -def _refresh_build_date_once(): +def _refresh_build_sizes(): + for lang in DOWNLOAD_LANGS: + for ext in DOWNLOAD_EXTS: + url = f"http://builds.kolibrios.org/{lang}/latest-{ext}.7z" + req = Request( + url, + method="HEAD", + headers={"User-Agent": "Mozilla/5.0"}, + ) + with urlopen(req, timeout=10) as r: + content_length = r.headers.get("Content-Length") + if not content_length: + continue + autobuild_sizes[lang][ext] = f"{int(content_length) / 1048576:.1f} MB" + + +def _refresh_autobuild_once(): global autobuild_date, autobuild_vers try: - from urllib.request import Request, urlopen req = Request( STATUS_URL, headers={ @@ -29,67 +57,34 @@ def _refresh_build_date_once(): r.headers.get_content_charset() or "utf-8", "replace" ) - ver_re = re.compile( - r"\b(\d+\.\d+\.\d+\.\d+\+\d{3,8}-[0-9a-fA-F]{7,40})\b" - ) last_ver = None - rows = re.findall(r"(]*>.*?)", html, flags=re.I | re.S) - for row in rows: + for row in ROW_RE.findall(html): cls = re.search(r'class\s*=\s*"([^"]*)"', row, flags=re.I) classes = cls.group(1).lower() if cls else "" if "commit" in classes: - mver = ver_re.search(row) + mver = VER_RE.search(row) if mver: last_ver = mver.group(1) continue if "success" not in classes: continue text = re.sub(r"<[^>]+>", " ", row) - mts = re.search( - r"\b(\d{4})\.(\d{2})\.(\d{2})\s+\d{2}:\d{2}:\d{2}\b", text - ) + mts = DATE_RE.search(text) if mts: - autobuild_date["YYYY"], autobuild_date["MM"], autobuild_date["DD"] = mts.groups() - else: - mds = re.search(r"\b(\d{2})\.(\d{2})\.(\d{4})\b", text) - if not mds: - return - autobuild_date["YYYY"], autobuild_date["MM"], autobuild_date["DD"] = ( - mds.group(3), - mds.group(2), - mds.group(1), - ) + autobuild_date = date(*map(int, mts.groups())) if last_ver: autobuild_vers = last_ver + _refresh_build_sizes() return - # Fallback for plain-text log format (no HTML table) - # Example: 2025.09.20 20:45:10 user πŸ’š Build processing completed successfully. Thank you. - log_line_re = re.compile( - r"^(\d{4})\.(\d{2})\.(\d{2})\s+\d{2}:\d{2}:\d{2}\s+(.*)$" - ) - for raw in html.splitlines(): - mline = log_line_re.match(raw.strip()) - if not mline: - continue - yyyy, mm, dd, rest = mline.groups() - mver = ver_re.search(rest) - if mver: - last_ver = mver.group(1) - if "Build processing completed successfully" in rest: - autobuild_date["YYYY"], autobuild_date["MM"], autobuild_date["DD"] = yyyy, mm, dd - if last_ver: - autobuild_vers = last_ver - return - except Exception: pass def _updater_loop(): while True: - _refresh_build_date_once() + _refresh_autobuild_once() time.sleep(STATUS_SEC) @@ -102,4 +97,4 @@ def ensure_started(): _started = True -_refresh_build_date_once() +_refresh_autobuild_once() diff --git a/modules/helpers.py b/modules/helpers.py index d6fa2b4..8d17330 100644 --- a/modules/helpers.py +++ b/modules/helpers.py @@ -19,5 +19,5 @@ def render_localized_template(lang, template_name): template_name, year=date.today().year, ), - remove_empty_space=True, + remove_empty_space=False, ) diff --git a/templates/download.html b/templates/download.html index 668b02f..760f221 100644 --- a/templates/download.html +++ b/templates/download.html @@ -56,7 +56,7 @@ ('es_ES', 'EspaΓ±ol') ) %} {{ lang }} {% if l == 'en_US' %} @@ -100,9 +100,9 @@ {{ _( 'downloads:download_description', kolibrios="{0}".format(_('title:index')), - zip="7zip", - gpl="GPLv2", - git="{0}".format(_('downloads:git-server')) + zip="7zip", + gpl="GPLv2", + git="{0}".format(_('downloads:git-server')) ) | safe }}

diff --git a/templates/tmpl/_article.htm b/templates/tmpl/_article.htm index 356d532..d1d8d1b 100644 --- a/templates/tmpl/_article.htm +++ b/templates/tmpl/_article.htm @@ -3,7 +3,7 @@ 'article:p1', kolibrios="{0}" .format(_('menu:kolibrios')), - drivers="{0}" + drivers="{0}" .format(_('article:drivers')) ) | safe }}

@@ -19,7 +19,7 @@ 'article:p2', kolibrios="{0}" .format(_('menu:kolibrios')), - fasm="FASM" + fasm="FASM" ) | safe }}

@@ -28,9 +28,9 @@ 'article:p3', kolibrios="{0}" .format(_('menu:kolibrios')), - feedback="{0}" + feedback="{0}" .format(_('article:feedback')), - help="{0}" + help="{0}" .format(_('article:help')) ) | safe }}

diff --git a/templates/tmpl/_footer.htm b/templates/tmpl/_footer.htm index a66f88f..ff74877 100644 --- a/templates/tmpl/_footer.htm +++ b/templates/tmpl/_footer.htm @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/templates/tmpl/_header.htm b/templates/tmpl/_header.htm index bf72471..95f707c 100644 --- a/templates/tmpl/_header.htm +++ b/templates/tmpl/_header.htm @@ -4,7 +4,7 @@ + content="kolibri, kolibrios, colibri, colibrios, ΠΊΠΎΠ»ΠΈΠ±Ρ€ΠΈ, колибриос, ΠΊΠ°Π»ΠΈΠ±Ρ€ΠΈ, калибриос, operating system, assembler, fasm, alternate, open source"> diff --git a/templates/tmpl/_menu.htm b/templates/tmpl/_menu.htm index d3fa582..103c9c4 100644 --- a/templates/tmpl/_menu.htm +++ b/templates/tmpl/_menu.htm @@ -1,13 +1,13 @@