[projects/pld-builder.new] queue.html: write the page in a module of its own
arekm
arekm at pld-linux.org
Thu Nov 12 09:18:34 CET 2026
commit 97cfd0b0de86cb3264f9a88dd02ab475e09ae384
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Nov 12 09:17:38 2026 +0100
queue.html: write the page in a module of its own
Moved out of request.py, among the request parsing code. The page is
the same, byte for byte.
PLD_Builder/bqueue.py | 24 +--------
PLD_Builder/queue_html.py | 129 ++++++++++++++++++++++++++++++++++++++++++++++
PLD_Builder/request.py | 97 ----------------------------------
3 files changed, 131 insertions(+), 119 deletions(-)
---
diff --git a/PLD_Builder/bqueue.py b/PLD_Builder/bqueue.py
index 737e5c2..9a9278d 100644
--- a/PLD_Builder/bqueue.py
+++ b/PLD_Builder/bqueue.py
@@ -9,6 +9,7 @@ from io import StringIO
# PLD_Builder:
import gpg
import log
+import queue_html
import request
import util
@@ -35,28 +36,7 @@ class B_Queue:
def dump_html(self, fname):
(fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
f = os.fdopen(fdno, "w")
- f.write("""
-<html>
- <head>
- <link rel="Shortcut Icon" href="//www.pld-linux.org/favicon.ico"/>
- <title>PLD builder queue</title>
- <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="style.css">
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
- <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.min.js"></script>
- <script type="text/javascript" src="script.js"></script>
- </head>
-<body>
-<div id="header">
- <div id="requesters-filter">Filter by requesters:<br></div>
-</div>
-<div id="content">
-"""
- )
- self.requests.reverse()
- for r in self.requests:
- r.dump_html(f)
- self.requests.reverse()
- f.write("</div></body></html>\n")
+ 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
new file mode 100644
index 0000000..abca824
--- /dev/null
+++ b/PLD_Builder/queue_html.py
@@ -0,0 +1,129 @@
+# vi: ts=8 sts=4 sw=4 et
+"""The queue as a web page: queue.html of the src builder."""
+
+import html
+import time
+import urllib.parse
+from datetime import datetime
+
+import pytz
+
+from config import config
+from request import escape, is_final
+
+
+# return timestamp with timezone information
+# so we could parse it in javascript
+def tzdate(t):
+ # %z of localtime(t) is the offset in effect at t, DST included
+ return time.strftime("%a %b %d %Y %H:%M:%S %z", time.localtime(t))
+
+# return date in iso8601 format
+def iso8601(ts, timezone='UTC'):
+ tz = pytz.timezone(timezone)
+ dt = datetime.fromtimestamp(ts, tz)
+ return dt.isoformat()
+
+
+def write(f, requests):
+ f.write("""
+<html>
+ <head>
+ <link rel="Shortcut Icon" href="//www.pld-linux.org/favicon.ico"/>
+ <title>PLD builder queue</title>
+ <link rel="stylesheet" type="text/css" charset="utf-8" media="all" href="style.css">
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.min.js"></script>
+ <script type="text/javascript" src="script.js"></script>
+ </head>
+<body>
+<div id="header">
+ <div id="requesters-filter">Filter by requesters:<br></div>
+</div>
+<div id="content">
+"""
+ )
+ for r in reversed(requests):
+ write_group(f, r)
+ f.write("</div></body></html>\n")
+
+
+def write_group(f, r):
+ flags = escape(' '.join(r.flags))
+ dt = escape(iso8601(r.time))
+ f.write(
+ f"<div id=\"{r.no}\" class=\"request {flags}\">\n"
+ f"<a href=\"#{r.no}\">{r.no}</a>. "
+ f"<time class=\"timeago\" title=\"{dt}\" datetime=\"{dt}\">{escape(tzdate(r.time))}</time> "
+ f"from <b class=requester>{escape(r.requester)}</b> "
+ f"<small><a href=\"srpms/{r.id}\">{r.id}</a>, "
+ f"prio={r.priority}, jobs={r.max_jobs}, {flags}</small>\n"
+ )
+ f.write("<ol>\n")
+ for b in r.batches:
+ write_batch(f, b, r.id)
+ f.write("</ol>\n")
+ f.write("</div>\n")
+
+
+def write_batch(f, b, rid):
+ quote = urllib.parse.quote
+ f.write("<li>\n")
+ if b.is_command():
+ flags = escape(' '.join(b.command_flags))
+ desc = f"SH: <pre>{escape(b.command)}</pre> flags: [{flags}]"
+ else:
+ package_url = ("http://git.pld-linux.org/gitweb.cgi"
+ f"?p=packages/{quote(b.spec[:-5])}.git"
+ f";f={quote(b.spec)};h={quote(b.branch)};a=shortlog")
+ link = f"<a href=\"{escape(package_url)}\">{escape(b.spec)} -r {escape(b.branch)}</a>"
+ rpmopts = b.bconds_string() + b.kernel_string() + b.target_string() + b.defines_string()
+ desc = f"{escape(b.src_rpm)} ({link}{escape(rpmopts)})"
+ f.write(f"{desc} <small>[")
+ builders = []
+ for builder in b.builders:
+ s = b.builders_status[builder]
+ if s.startswith("OK"):
+ c = "green"
+ elif s.startswith("FAIL"):
+ c = "red"
+ elif s.startswith("SKIP"):
+ c = "blue"
+ elif s.startswith("UNSUPP"):
+ c = "fuchsia"
+ elif s != "?":
+ c = "darkorange"
+ else:
+ c = "black"
+ link_pre = ""
+ link_post = ""
+ if is_final(s) and len(b.spec) > 5:
+ if b.is_command():
+ bl_name = "command"
+ else:
+ bl_name = b.spec[:len(b.spec)-5]
+ lin_ar = builder.replace('noauto-','')
+ is_ok = 0
+ if s.startswith("OK"):
+ is_ok = 1
+ bld = lin_ar.split('-')
+ tree_name = '-'.join(bld[:-1])
+ tree_arch = '-'.join(bld[-1:])
+ link_pre = f"<a href=\"{config.buildlogs}/index.php?dist={quote(tree_name)}&arch={quote(tree_arch)}" \
+ f"&ok={is_ok}&name={quote(bl_name)}&id={quote(rid)}&action=tail\">"
+ link_post = "</a>"
+
+ def ftime(s):
+ t = float(s)
+ if t > 0:
+ return time.asctime(time.localtime(t))
+ else:
+ return 'N/A'
+
+ tooltip = (f"last update: {ftime(b.builders_status_time[builder])}\n"
+ f"build time: {ftime(b.builders_status_buildtime[builder])}")
+ builders.append(link_pre +
+ f"<font color='{c}'><b title=\"{html.escape(tooltip, True)}\">"
+ f"{escape(builder)}:{escape(s)}</b></font>"
+ + link_post)
+ f.write("{}]</small></li>\n".format(' '.join(builders)))
diff --git a/PLD_Builder/request.py b/PLD_Builder/request.py
index c496ed9..915a9d6 100644
--- a/PLD_Builder/request.py
+++ b/PLD_Builder/request.py
@@ -1,23 +1,17 @@
# vi: ts=8 sts=4 sw=4 et
import fnmatch
-import html
import os
import re
import tempfile
import time
-import urllib.parse
import xml.sax.saxutils
-from datetime import datetime
from xml.dom.minidom import Element, parseString
-import pytz
-
import chroot
import log
import util
from acl import acl
-from config import config
__all__ = ['parse_request', 'parse_requests']
@@ -51,18 +45,6 @@ def escape(s):
# quotes too: values are also written into quoted attributes
return xml.sax.saxutils.escape(s, {"'": "'", '"': """})
-# return timestamp with timezone information
-# so we could parse it in javascript
-def tzdate(t):
- # %z of localtime(t) is the offset in effect at t, DST included
- return time.strftime("%a %b %d %Y %H:%M:%S %z", time.localtime(t))
-
-# return date in iso8601 format
-def iso8601(ts, timezone='UTC'):
- tz = pytz.timezone(timezone)
- dt = datetime.fromtimestamp(ts, tz)
- return dt.isoformat()
-
# what a builder reports before a final status, in the order it goes through them: waiting,
# building, built with its files still to be sent
PROGRESS_STATUSES = ("?", "BUILDING", "UPLOADING")
@@ -133,23 +115,6 @@ class Group:
b.dump(f)
f.write("\n")
- def dump_html(self, f):
- flags = escape(' '.join(self.flags))
- dt = escape(iso8601(self.time))
- f.write(
- f"<div id=\"{self.no}\" class=\"request {flags}\">\n"
- f"<a href=\"#{self.no}\">{self.no}</a>. "
- f"<time class=\"timeago\" title=\"{dt}\" datetime=\"{dt}\">{escape(tzdate(self.time))}</time> "
- f"from <b class=requester>{escape(self.requester)}</b> "
- f"<small><a href=\"srpms/{self.id}\">{self.id}</a>, "
- f"prio={self.priority}, jobs={self.max_jobs}, {flags}</small>\n"
- )
- f.write("<ol>\n")
- for b in self.batches:
- b.dump_html(f, self.id)
- f.write("</ol>\n")
- f.write("</div>\n")
-
def write_to(self, f):
f.write(f"""
<group id="{self.id}" no="{self.no}" flags="{escape(' '.join(self.flags))}">
@@ -284,68 +249,6 @@ class Batch:
def is_command(self):
return self.command != ""
- def dump_html(self, f, rid):
- quote = urllib.parse.quote
- f.write("<li>\n")
- if self.is_command():
- flags = escape(' '.join(self.command_flags))
- desc = f"SH: <pre>{escape(self.command)}</pre> flags: [{flags}]"
- else:
- package_url = ("http://git.pld-linux.org/gitweb.cgi"
- f"?p=packages/{quote(self.spec[:-5])}.git"
- f";f={quote(self.spec)};h={quote(self.branch)};a=shortlog")
- link = f"<a href=\"{escape(package_url)}\">{escape(self.spec)} -r {escape(self.branch)}</a>"
- rpmopts = self.bconds_string() + self.kernel_string() + self.target_string() + self.defines_string()
- desc = f"{escape(self.src_rpm)} ({link}{escape(rpmopts)})"
- f.write(f"{desc} <small>[")
- builders = []
- for b in self.builders:
- s = self.builders_status[b]
- if s.startswith("OK"):
- c = "green"
- elif s.startswith("FAIL"):
- c = "red"
- elif s.startswith("SKIP"):
- c = "blue"
- elif s.startswith("UNSUPP"):
- c = "fuchsia"
- elif s != "?":
- c = "darkorange"
- else:
- c = "black"
- link_pre = ""
- link_post = ""
- if is_final(s) and len(self.spec) > 5:
- if self.is_command():
- bl_name = "command"
- else:
- bl_name = self.spec[:len(self.spec)-5]
- lin_ar = b.replace('noauto-','')
- is_ok = 0
- if s.startswith("OK"):
- is_ok = 1
- bld = lin_ar.split('-')
- tree_name = '-'.join(bld[:-1])
- tree_arch = '-'.join(bld[-1:])
- link_pre = f"<a href=\"{config.buildlogs}/index.php?dist={quote(tree_name)}&arch={quote(tree_arch)}" \
- f"&ok={is_ok}&name={quote(bl_name)}&id={quote(rid)}&action=tail\">"
- link_post = "</a>"
-
- def ftime(s):
- t = float(s)
- if t > 0:
- return time.asctime(time.localtime(t))
- else:
- return 'N/A'
-
- tooltip = (f"last update: {ftime(self.builders_status_time[b])}\n"
- f"build time: {ftime(self.builders_status_buildtime[b])}")
- builders.append(link_pre +
- f"<font color='{c}'><b title=\"{html.escape(tooltip, True)}\">"
- f"{escape(b)}:{escape(s)}</b></font>"
- + link_post)
- f.write("{}]</small></li>\n".format(' '.join(builders)))
-
def rpmbuild_opts(self):
"""
return all rpmbuild options related to this build
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/9c47734c3e1a74461984048eaf31b4d1efc7d2a3
More information about the pld-cvs-commit
mailing list