[projects/pld-builder.new] rebuild-kernel-packages: wait for the src builder without Enter

arekm arekm at pld-linux.org
Sun Nov 8 00:32:48 CET 2026


commit 57a7c3ca1574889dd9cc4262b88b6eab3b73d628
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sun Nov 8 00:02:15 2026 +0100

    rebuild-kernel-packages: wait for the src builder without Enter
    
    After the request for the kernel packages the script waited for Enter.
    Now it checks the src builder's queue.gz every 15 s and sends the builds
    once the request appears there, which happens only when the command
    succeeded. Enter still goes on at once. A failed command never appears,
    so after --wait seconds (default 30 min) Enter is needed again.
    --queue-url sets the queue.gz address; --dry-run no longer asks.

 client/rebuild-kernel-packages.py | 74 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 2 deletions(-)
---
diff --git a/client/rebuild-kernel-packages.py b/client/rebuild-kernel-packages.py
index aa1d89e..6c5ed94 100755
--- a/client/rebuild-kernel-packages.py
+++ b/client/rebuild-kernel-packages.py
@@ -4,13 +4,23 @@
 import argparse
 import collections
 import functools
+import gzip
+import http.client
 import os
+import re
+import select
 import shlex
 import subprocess
 import sys
+import time
+import urllib.request
+from xml.dom import minidom
+from xml.parsers.expat import ExpatError
 
 import rpm
 
+QUEUE_POLL_INTERVAL = 15  # seconds between queue.gz checks
+
 supported_kernels = ['head', '6.18', '6.12', '6.6', '6.1', '5.15', '5.10']
 
 packages = collections.OrderedDict([
@@ -106,6 +116,49 @@ def fetch_package(name, spec, branch, verbose=False):
             return
         run_command(["/usr/bin/git", "-C", gitdir, "merge", "--ff-only", "@{upstream}"], verbose=verbose)
 
+def request_published(queue_url, group_id):
+    """Is group_id in the src builder's queue.gz? It gets there only once all went well."""
+    req = urllib.request.Request(queue_url, headers={"Cache-Control": "no-cache", "Pragma": "no-cache"})
+    with urllib.request.urlopen(req, timeout=20) as f:
+        text = gzip.decompress(f.read()).decode("utf-8")
+    # the plain queue comes first, then its signed copy
+    m = re.match(r"(<queue>.*?</queue>)", text, re.DOTALL)
+    if not m:
+        raise ValueError("no <queue> in it")
+    groups = minidom.parseString(m.group(1)).getElementsByTagName("group")
+    return any(g.getAttribute("id") == group_id for g in groups)
+
+def wait_for_request(queue_url, group_id, timeout):
+    """Return once the src builder has run group_id or Enter is pressed."""
+    print(f"\nWaiting up to {timeout}s for {group_id} in {queue_url}; press Enter to go on without waiting",
+          end="", flush=True)
+    deadline = time.monotonic() + timeout
+    stdin_open = True
+    while True:
+        try:
+            if request_published(queue_url, group_id):
+                print(" done.")
+                return
+            print(".", end="", flush=True)
+        # EOFError: a truncated download
+        except (OSError, EOFError, ValueError, ExpatError, http.client.HTTPException) as e:
+            print(f"\nCannot read {queue_url}: {e}", flush=True)
+        left = deadline - time.monotonic()
+        if left <= 0:
+            break
+        if not stdin_open:
+            time.sleep(min(left, QUEUE_POLL_INTERVAL))
+        elif select.select([sys.stdin], [], [], min(left, QUEUE_POLL_INTERVAL))[0]:
+            if sys.stdin.readline():
+                print("\nGoing on without waiting.")
+                return
+            stdin_open = False
+    # a failed command is never published: queue.gz alone cannot tell it from a busy builder
+    print(f"\nNot in the queue after {timeout}s: the command failed or the src builder is busy.")
+    if not stdin_open:
+        sys.exit("No Enter can come from a closed stdin; builds not sent.")
+    input("Press Enter after src builder updates kernel packages...")
+
 def csv_list(string):
     return string.split(',')
 
@@ -165,8 +218,19 @@ def main():
     parser.add_argument('--dry-run',
             action='store_true',
             help='Do not run builder commands, just show them (default: %(default)s)')
+    parser.add_argument('-w', '--wait',
+            default=1800,
+            type=int,
+            metavar='SECS',
+            help='How long to wait for the src builder before asking for Enter (default: %(default)s)')
+    parser.add_argument('--queue-url',
+            metavar='URL',
+            help='queue.gz of the src builder (default: https://srcbuilder.pld-linux.org/DIST/queue.gz)')
     args = parser.parse_args()
 
+    if not args.queue_url:
+        args.queue_url = f'https://srcbuilder.pld-linux.org/{args.dist}/queue.gz'
+
     build_mode = '-r'
     if args.test_build:
         build_mode = '-t'
@@ -235,8 +299,14 @@ def main():
                     dist=args.dist,
                     source_packages=' '.join(source_packages),
                 ))
-        run_command(shlex.split(command), verbose=args.verbose, dry_run=args.dry_run, quiet=False)
-        input('\nPress Enter after src builder updates kernel packages...')
+        sent, out = run_command(shlex.split(command), verbose=args.verbose, dry_run=args.dry_run, quiet=False)
+        group_id = re.search(r'Queue-ID: ([0-9a-f-]+)', out or '')
+        if args.dry_run:
+            print(f'Would wait up to {args.wait}s for the request in {args.queue_url}')
+        elif sent and group_id:
+            wait_for_request(args.queue_url, group_id.group(1), args.wait)
+        else:
+            input('\nPress Enter after src builder updates kernel packages...')
 
     for pkg, name, spec, branch, selected_kernels in builds:
         if args.test_build:
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/0fe372e62d4e92cd30ed562a93b2531e2d750ed1



More information about the pld-cvs-commit mailing list