Files
clipper-fm1/web/make_site.py
T
isod89andClaude Opus 5.5 a01c72ae5e Clipper 0.1: its own name, logo and folder (no confusion with SLOOP); overflow guards
- Identity: CLIPPER 0.1 on the boot screen (a three-masted clipper in the track colours, the "clipper"
  wordmark), ABOUT, the USB rescue screen, the visualiser; the editor (Clipper Editor, its logo and
  messages), the installer page and the site; INSTALL-CLIPPER.bat / build-clipper.ps1 / OPEN-EDITOR.bat
  on port 8767 (SLOOP: 8766), the voices as an argument (8, 12, 16), the SDK files taken from the SLOOP
  folder the first time.
- Docs: README.md and DEMARRAGE-RAPIDE-FR.md for Clipper (install, play, the CPU test); SLOOP's manuals in
  docs/sloop; SLOOP's prebuilt site and logos removed.
- HYBRID: F1's output into F2 (series) bounded, the parallel balance at a quarter scale, the ring's inputs
  bounded: every product in 32 bits at any setting (checked under UBSan over every routing and filter pair
  at extreme values); the mixer keeps one more bit of headroom in 12 / 16-voice builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RDUenQzjQ4Kk2jQVG85bwq
2026-10-09 19:12:26 -04:00

93 lines
4.4 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
# Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments
"""Make the site (GitHub Pages):
index.html redirect to the installer
firmware/felucca-VER.fwsc the package
webapp/installer/index.html index_pkg.html with fm1pkg.js, fm1ota.js and the metadata inlined
webapp/editor/index.html editor.html (+ fukiai.ttf, FUKIAI-LICENSE.txt)
src/ not touched
web/make_site.py build/felucca-X.Y.fwsc X.Y OUT_DIR [--beta]
(--beta: web/beta_banner.html at the top of the installer: the beta channel, docs/beta)
The package identity (FM-1_9xx) is read from the package; the device reports it
after the install.
"""
import hashlib
import json
import re
import shutil
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
BLOCKS, BLK, KEEP = 20, 0x30, 0x2F
def strip_module(src):
src = re.sub(r"^export\s+", "", src, flags=re.M)
return re.sub(r"^import .*?;\n", "", src, flags=re.M)
def product_of(raw):
"""the package identity: one marker byte after each of the first 20 blocks (fm1pkg.js productOf)"""
return "".join(chr((m - i - 1) & 0xFF) for i in range(BLOCKS) if (m := raw[i * BLK + KEEP]) != 0x7D)
def main(pkg, version, out):
pkg, out = Path(pkg), Path(out)
raw = pkg.read_bytes()
product = product_of(raw)
if not re.fullmatch(r"FM-1_9\d\d", product):
raise SystemExit(f"{pkg}: identity {product!r} is not a Felucca package (FM-1_9xx)")
if b"FELUCCA-LOADER-1" not in raw: # marker of firmware/loader
raise SystemExit(f"{pkg}: no Felucca update loader in it")
html = (HERE / "index_pkg.html").read_text(encoding="utf-8")
lib = strip_module((HERE / "fm1pkg.js").read_text(encoding="utf-8")) + "\n" + \
strip_module((HERE / "fm1ota.js").read_text(encoding="utf-8"))
name = f"clipper-{re.sub(r'[^A-Za-z0-9.-]', '-', version)}.fwsc"
meta = json.dumps({"version": version, "product": product, "pkg": "../../firmware/" + name,
"sha256": hashlib.sha256(raw).hexdigest()}) # the page checks the download against it
for mark in ("/*LIB*/", "/*META*/"):
if html.count(mark) != 1:
raise SystemExit(f"index_pkg.html must contain {mark} once; update make_site.py")
html = html.replace("/*LIB*/", lib).replace("/*META*/", meta)
logo = HERE.parent / "assets" / "logo" / "clipper-logo.svg" # the Clipper logo, inline
html = html.replace("<!--LOGO-->", logo.read_text(encoding="utf-8") if logo.exists() else "<b>Clipper</b>")
inst, ed, fw = out / "webapp" / "installer", out / "webapp" / "editor", out / "firmware"
for d in (inst, ed, fw):
d.mkdir(parents=True, exist_ok=True)
guide = HERE.parent / "output/pdf/Studio-0.3-guide-rapide-FR.pdf"
guide_link = ""
if guide.exists() and "--studio-guide" in sys.argv: # LIVE: that guide describes the removed RYTHME tab
shutil.copy(guide, out / guide.name)
guide_link = '<p lang="fr"><a href="../../' + guide.name + '">Guide rapide illustré (PDF, 4 pages)</a></p>'
html = html.replace("<!--STUDIO_GUIDE-->", guide_link)
banner = ""
if "--beta" in sys.argv: # the beta channel (docs/beta): what it is, what it implies
notes = HERE / "beta_banner.html"
banner = notes.read_text(encoding="utf-8") if notes.exists() else "<p><b>BETA</b></p>"
html = html.replace("<!--BANNER-->", banner)
for old in list(fw.glob("felucca-*.fwsc")) + list(fw.glob("sloop-*.fwsc")) + list(fw.glob("clipper-*.fwsc")): # one package: the current one
old.unlink()
(inst / "index.html").write_text(html, encoding="utf-8")
shutil.copy(pkg, fw / name)
shutil.copy(HERE / "editor.html", ed / "index.html")
for f in ("fukiai.ttf", "FUKIAI-LICENSE.txt"):
if (HERE / f).exists():
shutil.copy(HERE / f, ed / f)
(out / "index.html").write_text(
'<!doctype html><meta charset="utf-8"><title>Clipper</title>'
'<meta http-equiv="refresh" content="0; url=webapp/installer/">'
'<a href="webapp/installer/">Clipper installer</a>\n', encoding="utf-8")
print(f"site: {out}: webapp/installer ({len(html)} B), webapp/editor, firmware/{name} ({len(raw)} B, {product})")
if __name__ == "__main__":
args = [a for a in sys.argv[1:] if a not in ("--studio-guide", "--beta")]
if len(args) != 3:
sys.exit(__doc__)
main(*args)