Files
steward/scripts/logo.py
T
abrown38andClaude Opus 5.5 3c0808591f Steward 0.1.0 (in development): a DHCPv4 server with a web UI, API and CLI
Subnets served per interface, pools, reservations, options at three
levels, leases in SQLite saved before the ACK, ping and decline conflict
checks, validated changes with history and undo, users and tokens, an
audit log, a Kea importer, a sandboxed systemd unit and Debian packages.
Tested with real udhcpc and dhcpcd clients in Docker (scripts/e2e.sh).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 12:14:07 +01:00

58 lines
2.0 KiB
Python

#!/usr/bin/env python3
# Builds the web UI's logo from the master, artwork/logo.svg (a key whose
# bow is a crown with Jarl's network nodes, in Jarl's blue and white):
#
# internal/web/static/assets/logo.svg the favicon (a copy)
# internal/web/static/assets/logo.js the shapes for the web UI, which
# draws them inline (brand.js), so the
# logo appears together with the page
#
# The master is hand-written SVG: <g> elements whose attributes apply to
# their <path> and <circle> children. Run from the repository root after
# changing it:
#
# python3 scripts/logo.py
import json
import os
import shutil
import sys
import xml.etree.ElementTree as ET
MASTER = "artwork/logo.svg"
OUT = "internal/web/static/assets"
SVG = "{http://www.w3.org/2000/svg}"
def shapes(el, inherited):
out = []
attrs = dict(inherited)
attrs.update({k: v for k, v in el.attrib.items() if k not in ("xmlns", "viewBox")})
tag = el.tag.replace(SVG, "")
if tag in ("path", "circle", "rect", "polygon"):
out.append([tag, attrs])
for child in el:
out.extend(shapes(child, attrs if tag == "g" else inherited))
return out
def main():
root = ET.parse(MASTER).getroot()
view_box = root.attrib["viewBox"]
items = []
for child in root:
items.extend(shapes(child, {}))
with open(os.path.join(OUT, "logo.js"), "w") as f:
f.write(f"// The Steward logo, from {MASTER} by scripts/logo.py; don't edit.\n"
"// brand.js draws it; logo.svg is the same picture.\n"
f"export const viewBox = {json.dumps(view_box)};\n"
"export const shapes = [\n"
+ "".join(f" {json.dumps(s)},\n" for s in items)
+ "];\n")
shutil.copyfile(MASTER, os.path.join(OUT, "logo.svg"))
for name in ("logo.svg", "logo.js"):
print(f"{OUT}/{name}: {os.path.getsize(os.path.join(OUT, name))} bytes")
if __name__ == "__main__":
sys.exit(main())