#!/usr/bin/env python3 """Write MANIFEST.md and index.html for the Tiny Linux source copy (run by fetch-sources.sh). python3 -I make-source-index.py /disk2/work/tinylinux-source Reads /*/SOURCE-INFO.txt (written by fetch-sources.sh) and lists every file with its size. The written offer and the contact address are set here (CONTACT, SITE). """ import html import os import sys import time CONTACT = "quantaprism.network@gmail.com" SITE = "QuantaPrism Code (code.quantaprism.com)" ORDER = ["linux-lts", "busybox", "tcc", "cmatrix", "seabios", "pyodide", "quantaprism-tinylinux", "alpine-apkindex"] OFFER = (f"{SITE} sends a small Linux system (\"Tiny Linux\") and a PC BIOS to your web browser. " "They contain free software under the GNU General Public License (GPL) and the GNU Lesser " "General Public License (LGPL). This page is the complete corresponding source code of " "exactly the versions we send: the source of each program, the build recipes and patches " "used to compile it, and our own build scripts. You may also ask us for a copy at " f"{CONTACT}; we will send it to you for no more than the cost of sending it. This offer is " "valid for at least three years after we last send the programs, to anyone who receives them.") def human(n): for unit in ("B", "KB", "MB", "GB"): if n < 1024 or unit == "GB": return f"{n:.0f} {unit}" if unit == "B" else f"{n:.1f} {unit}" n /= 1024 def read_info(d): info = {} with open(os.path.join(d, "SOURCE-INFO.txt"), encoding="utf-8") as f: for line in f: if "=" in line: k, v = line.rstrip("\n").split("=", 1) info[k] = v return info def main(root): pkgs = [] for name in sorted(os.listdir(root)): d = os.path.join(root, name) if not os.path.isfile(os.path.join(d, "SOURCE-INFO.txt")): continue info = read_info(d) files = [] for dirpath, _, names in os.walk(d): for n in names: p = os.path.join(dirpath, n) files.append((os.path.relpath(p, d), os.path.getsize(p))) files.sort() info.update(dir=name, files=files, size=sum(s for _, s in files)) pkgs.append(info) key = lambda p: ORDER.index(p["name"]) if p["name"] in ORDER else len(ORDER) pkgs.sort(key=key) total = sum(p["size"] for p in pkgs) today = time.strftime("%Y-%m-%d") # MANIFEST.md m = [f"# Tiny Linux corresponding source ({today})", "", OFFER, "", f"Total: {human(total)} ({total} bytes). Checksums: `SHA256SUMS` (all files) and " "`/SHA256SUMS`. Refetch with `CodeSite/tools/tinylinux/fetch-sources.sh`.", "", "| Folder | Package | Version | Licence | Size |", "|---|---|---|---|---|"] for p in pkgs: m.append(f"| {p['dir']} | {p['name']} | {p['version']} | {p['licence']} | {human(p['size'])} |") for p in pkgs: m += ["", f"## {p['dir']}", "", f"- Shipped as: {p['binaries']}", f"- Licence: {p['licence']}", f"- Build recipe from: {p['recipe']}"] for u in p.get("upstream", "").split(): f_, _, url = u.partition("=") m.append(f"- `{f_}` downloaded from {url}") m.append(f"- Checked: {p['checked']}") m.append("- Files: " + ", ".join(f"`{f}` ({human(s)})" for f, s in p["files"])) with open(os.path.join(root, "MANIFEST.md"), "w", encoding="utf-8") as f: f.write("\n".join(m) + "\n") # index.html e = html.escape rows, details = [], [] for p in pkgs: rows.append(f"{e(p['name'])}{e(p['version'])}" f"{e(p['licence'])}{human(p['size'])}") links = "".join(f"
  • {e(f)} {human(s)}
  • " for f, s in p["files"]) ups = "".join(f"
  • {e(u.partition('=')[0])} from {e(u.partition('=')[2])}
  • " for u in p.get("upstream", "").split()) details.append( f"

    {e(p['dir'])}

    " f"

    Shipped as: {e(p['binaries'])}
    Licence: {e(p['licence'])}
    " f"Build recipe: {e(p['recipe'])}
    " f"Checked: {e(p['checked'])}

    " + (f"
      {ups}
    " if ups else "") + f"
    {len(p['files'])} files, {human(p['size'])}
      {links}
    ") page = f""" Tiny Linux source code

    Tiny Linux source code

    {e(OFFER)}

    {''.join(rows)}
    PackageVersionLicenceSize
    Total{human(total)}

    MANIFEST.md (where every file came from) ยท SHA256SUMS (check with sha256sum -c SHA256SUMS)

    How to build: each Alpine folder holds the APKBUILD with its patches and configs next to the upstream files; in an i386 Alpine Linux 3.22 system run abuild -r in that folder. The kernel shipped is the virt flavour (config virt.x86.config). Tiny Linux itself is put together by build.sh in the quantaprism-tinylinux folder.

    {''.join(details)}
    """ with open(os.path.join(root, "index.html"), "w", encoding="utf-8") as f: f.write(page) print(f"{len(pkgs)} folders, {human(total)}") if __name__ == "__main__": main(sys.argv[1])