[projects/pld-builder.new] queue.html: put the stylesheet and script into the page

arekm arekm at pld-linux.org
Thu Nov 12 11:36:18 CET 2026


commit 7bddef93f23d3d06baaa039d678b6a907eac8bd4
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Nov 12 11:35:30 2026 +0100

    queue.html: put the stylesheet and script into the page
    
    The page was written by two processes, the src builder started by cron
    and the long running request server, and each copied style.css and
    script.js from disk into www. After an update the server, until
    restarted, wrote the page its old code draws next to the stylesheet of
    the new one, and the page fell apart. Now each process reads both when
    it starts and puts them into the page it writes, so a page always comes
    with the stylesheet and script of the code that wrote it.

 PLD_Builder/bqueue.py     |  2 +-
 PLD_Builder/queue_html.py | 36 ++++++++++++++----------------------
 2 files changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/PLD_Builder/bqueue.py b/PLD_Builder/bqueue.py
index e535a9f..666a7dc 100644
--- a/PLD_Builder/bqueue.py
+++ b/PLD_Builder/bqueue.py
@@ -36,7 +36,7 @@ class B_Queue:
     def dump_html(self, fname):
         (fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
         f = os.fdopen(fdno, "w", encoding="utf-8")
-        queue_html.write(f, self.requests, os.path.dirname(fname))
+        queue_html.write(f, self.requests)
         f.flush()
         os.fsync(f.fileno())
         f.close()
diff --git a/PLD_Builder/queue_html.py b/PLD_Builder/queue_html.py
index 6898be2..870b15c 100644
--- a/PLD_Builder/queue_html.py
+++ b/PLD_Builder/queue_html.py
@@ -7,11 +7,10 @@
     legend              a request with its parts named instead of filled in
 
 style.css draws it. script.js fills in the times that go on running ("5 min ago") and filters
-the requests.
+the requests. Both go into the page itself.
 """
 
 import os
-import tempfile
 import time
 import urllib.parse
 from datetime import datetime
@@ -22,29 +21,22 @@ from request import escape, is_final
 quote = urllib.parse.quote
 
 
-def write(f, requests, www):
-    """Write the page, which is to be in www, and put the files it uses there"""
-    f.write(page(requests, {name: publish(name, www) for name in ("style.css", "script.js")}))
+def asset(name):
+    with open(os.path.join(os.path.dirname(__file__), name), encoding="utf-8") as f:
+        return f.read()
 
 
-def publish(name, www):
-    """Copy a file of the page to www when it changed, and say how the page refers to it
+# read when the module loads: a long running request server goes on writing pages its own code
+# draws, whatever an update has put on disk since
+STYLE = asset("style.css")
+SCRIPT = asset("script.js")
 
-    The address changes with the copy, so a browser fetches it again rather than draw the page
-    with an older one it keeps.
-    """
-    src = os.path.join(os.path.dirname(__file__), name)
-    dst = os.path.join(www, name)
-    if not os.path.exists(dst) or os.stat(src).st_mtime > os.stat(dst).st_mtime:
-        (fd, tmp) = tempfile.mkstemp(dir=www)
-        with open(src) as r, os.fdopen(fd, "w") as w:
-            w.write(r.read())
-        os.chmod(tmp, 0o644)
-        os.rename(tmp, dst)
-    return f"{name}?{int(os.stat(dst).st_mtime)}"
 
+def write(f, requests):
+    f.write(page(requests))
 
-def page(requests, files):
+
+def page(requests):
     newest_first = sorted(requests, key=lambda r: r.no, reverse=True)
     return (
         '<!DOCTYPE html>\n'
@@ -54,8 +46,7 @@ def page(requests, files):
         '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
         '<link rel="Shortcut Icon" href="//www.pld-linux.org/favicon.ico">\n'
         '<title>PLD builder queue</title>\n'
-        f'<link rel="stylesheet" href="{files["style.css"]}">\n'
-        f'<script src="{files["script.js"]}" defer></script>\n'
+        f'<style>\n{STYLE}</style>\n'
         '</head>\n'
         '<body>\n'
         '<header id="top">\n'
@@ -70,6 +61,7 @@ def page(requests, files):
         + requests_by_day(newest_first)
         + LEGEND.format(zone=time.strftime("%Z"))
         + '</main>\n'
+        + f'<script>\n{SCRIPT}</script>\n'
         '</body>\n'
         '</html>\n'
     )
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/7bddef93f23d3d06baaa039d678b6a907eac8bd4



More information about the pld-cvs-commit mailing list