Artifact ec4b96493ec9d3dcc32cd72a4343bad802fa30a57d3585457618c981ddacb102:
- Executable file
skin/apply.py
— part of check-in
[243e1f93d6]
at
2026-12-01 11:37:26
on branch trunk
— Support Tcl custom ticket schema and add tcl mirror metadata
- Treat Deleted and Rejected as closed statuses, and Pending as review/warn - Order SourceForge numeric priorities (9 Immediate..1 Zero) alongside stock labels - Derive board status/priority/top-subsystem columns dynamically and show match totals when capped at 200 - Honor cmimetype on initial ticket descriptions and show optional assignee/submitter/closer fields - Allow .meta line-5 flags (skin-tickets) to opt custom-table mirrors into skinned ticket templates (user: dmestas, size: 9312) [annotate] [blame] [check-ins using]
#!/usr/bin/env python3 """Push skin files to all repos and regenerate the landing page repo grid.""" import sqlite3, time, os, glob, re, html, hashlib REPOS_DIR = "/var/fossil/repos" SKIN_DIR = os.path.dirname(os.path.abspath(__file__)) WWW_DIR = os.path.join(os.path.dirname(SKIN_DIR), "www") INDEX_HTML = os.path.join(WWW_DIR, "index.html") # Icons: skin/icons/<name>.svg (Phosphor duotone, MIT). A meta file's first line names one; # any other text is used as-is (an emoji). Default when nothing is set: ICONS_DIR = os.path.join(SKIN_DIR, "icons") DEFAULT_ICON = "package" def icon_html(icon): """Inline the named SVG icon, or return the text escaped (emoji fallback).""" path = os.path.join(ICONS_DIR, f"{icon}.svg") if re.fullmatch(r"[a-z0-9-]+", icon) and os.path.exists(path): svg = open(path).read() svg = re.sub(r"<!--.*?-->", "", svg, flags=re.S) svg = svg.replace("<svg", '<svg aria-hidden="true"', 1) return re.sub(r"\s+", " ", svg).strip() return html.escape(icon) # Default public caps: wiki readable only DEFAULT_PUBLIC_CAPS = "jh" def sidecar_meta(fossil_path): """Read optional sidecar metadata for one repo. Format: line 1: icon name (skin/icons/<name>.svg) or emoji line 2: landing-page description line 3: optional Fossil caps for the "nobody" user (not logged in) line 4: optional Fossil caps for the "anonymous" user (defaults to line 3) line 5: optional space/comma-separated flags (e.g. "skin-tickets") """ meta_path = fossil_path.replace(".fossil", ".meta") icon = DEFAULT_ICON desc = "" nobody_caps = DEFAULT_PUBLIC_CAPS anon_caps = None flags = set() if os.path.exists(meta_path): lines = open(meta_path).read().splitlines() if len(lines) >= 1 and lines[0].strip(): icon = lines[0].strip() if len(lines) >= 2 and lines[1].strip(): desc = lines[1].strip() if len(lines) >= 3 and lines[2].strip(): nobody_caps = lines[2].strip() if len(lines) >= 4 and lines[3].strip(): anon_caps = lines[3].strip() if len(lines) >= 5 and lines[4].strip(): flags = {f for f in re.split(r"[\s,]+", lines[4].strip()) if f} return icon, desc, nobody_caps, anon_caps or nobody_caps, flags # ── Skin parts pushed to every repo ─────────────────────────────────────── parts = { "css": open(f"{SKIN_DIR}/css.txt").read(), # The script's address carries a hash of it, so a changed a11y.js gets a new # URL that neither Cloudflare nor browsers have cached (both keep it 4 hours). "header": open(f"{SKIN_DIR}/header.txt").read().replace( 'src="/a11y.js"', 'src="/a11y.js?v=%s"' % hashlib.sha256(open(f"{WWW_DIR}/a11y.js", "rb").read()).hexdigest()[:10]), "footer": open(f"{SKIN_DIR}/footer.txt").read(), # Fossil reads these from the "details" setting. white-foreground makes it send # dark user and branch tints meant for light text instead of pastels. "details": ( "timeline-arrowheads: 1\n" "timeline-circle-nodes: 1\n" "timeline-color-graph-lines: 1\n" "white-foreground: 1\n" ), "logo-image": open(f"{SKIN_DIR}/logo.png", "rb").read(), "logo-mimetype": "image/png", # Fossil's default main menu plus a Search entry (search is enabled per repo with fts-config) "mainmenu": ( "Home /home * {}\n" "Timeline /timeline {o r j} {}\n" "Files /dir?ci=tip oh desktoponly\n" "Branches /brlist o wideonly\n" "Tags /taglist o wideonly\n" "Forum /forum {@2 3 4 5 6} wideonly\n" "Chat /chat C wideonly\n" "Tickets /reportlist r wideonly\n" "Wiki /wiki j wideonly\n" "Search /search {o r j 2} wideonly\n" "Admin /setup {a s} desktoponly\n" "Logout /logout L wideonly\n" "Login /login !L wideonly\n" ), } # Ticket UI templates (Option B): applied to repos using the default ticket # schema. Repos with a custom ticket-table (e.g. upstream mirrors) are left alone. TICKETS_DIR = os.path.join(SKIN_DIR, "tickets") ticket_parts = {} for key, fname in ( ("ticket-reportlist", "reportlist.th1"), ("ticket-viewpage", "viewpage.th1"), ("ticket-newpage", "newpage.th1"), ("ticket-editpage", "editpage.th1"), ): p = os.path.join(TICKETS_DIR, fname) if os.path.exists(p): ticket_parts[key] = open(p).read() # Home page: the first of these wiki pages that exists, unless index-page is already set. HOME_PAGES = ("Home", "index") # ── Apply skin to repos ──────────────────────────────────────────────────── repos = sorted(glob.glob(f"{REPOS_DIR}/*.fossil")) mtime = int(time.time()) for repo in repos: _, _, nobody_caps, anon_caps, flags = sidecar_meta(repo) con = sqlite3.connect(repo) con.execute("DELETE FROM config WHERE name='skin-detail'") # a name Fossil never read for name, value in parts.items(): con.execute("INSERT OR REPLACE INTO config(name,value,mtime) VALUES(?,?,?)", (name, value, mtime)) has_custom_tkt_table = con.execute( "SELECT 1 FROM config WHERE name='ticket-table'" ).fetchone() if ticket_parts and (not has_custom_tkt_table or "skin-tickets" in flags): for name, value in ticket_parts.items(): con.execute("INSERT OR REPLACE INTO config(name,value,mtime) VALUES(?,?,?)", (name, value, mtime)) # Public access defaults to wiki-only unless a repo's .meta file overrides it. con.execute("UPDATE user SET cap=?, mtime=? WHERE login='nobody'", (nobody_caps, mtime)) con.execute("UPDATE user SET cap=?, mtime=? WHERE login='anonymous'", (anon_caps, mtime)) if not con.execute("SELECT 1 FROM config WHERE name='index-page'").fetchone(): pages = {r[0] for r in con.execute("SELECT substr(tagname,6) FROM tag WHERE tagname LIKE 'wiki-%'")} for page in HOME_PAGES: if page in pages: con.execute("INSERT INTO config(name,value,mtime) VALUES('index-page',?,?)", (f"/wiki?name={page}", mtime)) print(f" home page of {os.path.basename(repo)} -> {page}") break con.commit() con.close() print(f" skinned {os.path.basename(repo)}") # ── Regenerate landing page repo grid ───────────────────────────────────── def repo_meta(fossil_path): """Read project-name and description from a .fossil file. Falls back to filename if not set. Also checks for an optional .meta file alongside the .fossil for icon/desc overrides.""" name = os.path.basename(fossil_path).replace(".fossil", "") desc = "" icon = DEFAULT_ICON # Read project-name from SQLite config try: con = sqlite3.connect(fossil_path) row = con.execute("SELECT value FROM config WHERE name='project-name'").fetchone() if row: name = row[0] row = con.execute("SELECT value FROM config WHERE name='project-description'").fetchone() if row and row[0]: desc = row[0] con.close() except Exception: pass # Optional sidecar file: /var/fossil/repos/<name>.meta # Format: # line 1: emoji icon # line 2: landing-page description # line 3/4: optional caps for nobody / anonymous meta_path = fossil_path.replace(".fossil", ".meta") if os.path.exists(meta_path): icon_override, desc_override, _, _, _ = sidecar_meta(fossil_path) icon = icon_override if desc_override: desc = desc_override return name, icon, desc def make_card(name, icon, desc, slug): esc_name = html.escape(name) esc_desc = html.escape(desc) esc_icon = icon_html(icon) return ( f' <a class="repo-card" href="/{slug}/">\n' f' <div class="repo-icon">{esc_icon}</div>\n' f' <div class="repo-info">\n' f' <div class="repo-name">{esc_name}</div>\n' f' <div class="repo-desc">{esc_desc}</div>\n' f' </div>\n' f' <span class="repo-arrow">→</span>\n' f' </a>' ) cards = [] for repo in repos: slug = os.path.basename(repo).replace(".fossil", "") name, icon, desc = repo_meta(repo) cards.append(make_card(name, icon, desc, slug)) grid_html = "\n\n".join(cards) index = open(INDEX_HTML).read() index = re.sub( r'<!-- REPO-GRID-START -->.*?<!-- REPO-GRID-END -->', f'<!-- REPO-GRID-START -->\n{grid_html}\n <!-- REPO-GRID-END -->', index, flags=re.DOTALL, ) open(INDEX_HTML, "w").write(index) print(" regenerated index.html") print("done.")