[projects/pld-ftp-admin] pfa-genindex: build each tree and arch as one job

arekm arekm at pld-linux.org
Tue Oct 27 10:56:17 CET 2026


commit 5d855689acd2ed0dc348517adcd64166d594afa7
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Oct 27 00:32:23 2026 +0100

    pfa-genindex: build each tree and arch as one job
    
    Prepares building several of them at once.  poldek and then createrepo_c
    now run for one tree and arch before the next, instead of poldek for all
    of them first; the indexes are the same.  The tools run without a shell:
    each command is printed as it starts and its duration replaces the
    output of time, without the old per-tree and per-index headers.
    
    Ctrl-C now stops the whole run, where os.system skipped only the running
    tool, so the trees are unlocked in a finally block.

 bin/pfa-genindex | 108 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 59 insertions(+), 49 deletions(-)
---
diff --git a/bin/pfa-genindex b/bin/pfa-genindex
index 0eed1ea..2926c22 100755
--- a/bin/pfa-genindex
+++ b/bin/pfa-genindex
@@ -3,7 +3,9 @@
 
 import argparse
 import os
+import subprocess
 import sys
+import time
 
 INDEXES = ('poldek', 'yum')
 
@@ -69,18 +71,6 @@ for tree in trees:
     checkdir(tree)
 
 ftpio.connect('gen-indexes')
-
-locked = []
-
-for tree in trees:
-    if ftpio.lock(tree, True):
-        locked.append(tree)
-    else:
-        print(f"ERR: {tree} tree already locked", file=sys.stderr)
-        for i in locked:
-            ftpio.unlock(i)
-        sys.exit(1)
-
 home = os.environ['HOME']
 
 os.umask(0o022)
@@ -89,52 +79,72 @@ os.nice(19)
 failed = []
 
 
-def run(what, cmd):
+def run(what, argv):
     # keep building the other indexes; every failure is reported at the end
-    rc = os.waitstatus_to_exitcode(os.system(cmd))
+    print(' '.join(argv), flush=True)
+    start = time.monotonic()
+    try:
+        rc = subprocess.call(argv)
+    except OSError as e:
+        # what the shell reported as "not found" before
+        print(f'{what}: {e}', file=sys.stderr)
+        rc = 127
+    if not quiet:
+        print(f'{what}: {time.monotonic() - start:.1f}s', flush=True)
     if rc != 0:
         failed.append(f'{what} exited with {rc}')
 
 
-if do_poldek:
-    poldek = f'{ftp_dir}.stat/bin/poldek-new --cachedir={home}/tmp/poldek --conf {ftp_dir}.stat/etc/poldek.conf --mkidxz'
+comps_file = f'{ftp_dir}.stat/repodata/comps.xml'
+poldek = [f'{ftp_dir}.stat/bin/poldek-new', f'--cachedir={home}/tmp/poldek', '--conf', f'{ftp_dir}.stat/etc/poldek.conf', '--mkidxz']
+yum = [f'{ftp_dir}.stat/bin/createrepo_c', '--database', '--update', '--skip-stat', '--workers=12', '--xz', f'--groupfile={comps_file}']
+
+
+def build(tree, arch):
+    """Builds the indexes of one tree and arch.
+
+    poldek goes first, as the freshness check of the repodata reads its index.
+    """
+    archdir = f'{ftp_dir}{tree}/{arch}'
+    dirs = ['RPMS']
+    if arch != 'noarch' and config.separate_debuginfo:
+        dirs.append('debuginfo')
 
+    if do_poldek:
+        for d in dirs:
+            run(f'{tree}/{arch}: poldek', poldek + ['-s', f'{archdir}/{d}/', '--mkidxz', '--mkidx-type', 'pndir'])
+
+    if do_yum:
+        poldek_idx = f'{archdir}/RPMS/packages.ndir.md'
+        repodata_idx = f'{archdir}/RPMS/repodata/repomd.xml'
+        if freshen and os.path.exists(poldek_idx) and os.path.exists(repodata_idx) \
+            and not os.path.getmtime(comps_file) > os.path.getmtime(repodata_idx) \
+            and not os.path.getmtime(poldek_idx) > os.path.getmtime(repodata_idx):
+            print(f'{tree}/{arch}: repodata indexes already fresh')
+            return
+        cachedir = f'{home}/tmp/createrepo/{tree}-{arch}'
+        # createrepo_c mkdirs only the last component of --cachedir
+        os.makedirs(os.path.dirname(cachedir), mode=0o711, exist_ok=True)
+        for d in dirs:
+            run(f'{tree}/{arch}: createrepo_c', yum + [f'--cachedir={cachedir}', f'{archdir}/{d}'])
+
+
+locked = []
+try:
     for tree in trees:
-        print(f'\n-------------------------- {tree} --------------------------')
-        for arch in all_ftp_archs:
-            print(f'\ngenerate poldek index for {arch}')
-            print(f'{poldek} -s {ftp_dir}{tree}/{arch}/RPMS/ --mkidxz --mkidx-type pndir')
-            run(f'{tree}/{arch}: poldek', f'{poldek} -s {ftp_dir}{tree}/{arch}/RPMS/ --mkidxz --mkidx-type pndir')
-            if arch != 'noarch' and config.separate_debuginfo:
-                run(f'{tree}/{arch}: poldek', f'{poldek} -s {ftp_dir}{tree}/{arch}/debuginfo/ --mkidxz --mkidx-type pndir')
-
-if do_yum:
-    run('comps.xml checkout', f'{"" if quiet else "set -x;"} cd {ftp_dir}.stat/repodata && git checkout {"--quiet" if quiet else ""} HEAD repodata/comps.xml')
-    yum = f'{ftp_dir}.stat/bin/createrepo_c --database --update --skip-stat --workers=12 --xz --groupfile={ftp_dir}.stat/repodata/comps.xml'
-    comps_file = f'{ftp_dir}.stat/repodata/comps.xml'
+        if not ftpio.lock(tree, True):
+            print(f"ERR: {tree} tree already locked", file=sys.stderr)
+            sys.exit(1)
+        locked.append(tree)
+    if do_yum:
+        run('comps.xml checkout', ['git', '-C', f'{ftp_dir}.stat/repodata', 'checkout'] + (['--quiet'] if quiet else []) + ['HEAD', 'repodata/comps.xml'])
     for tree in trees:
-        print(f'\n-------------------------- {tree} --------------------------')
-        cachedir = f'{home}/tmp/createrepo/{tree}'
-        # createrepo_c mkdirs only the last component of --cachedir={cachedir}-{arch}
-        os.makedirs(os.path.dirname(cachedir), mode=0o711, exist_ok=True)
-        treedir = f"{ftp_dir}{tree}"
         for arch in all_ftp_archs:
-            print(f'\ngenerate repodata for {arch} using createrepo')
-            archdir = f"{treedir}/{arch}"
-            poldek_idx = f"{archdir}/RPMS/packages.ndir.md"
-            repodata_idx = f"{archdir}/RPMS/repodata/repomd.xml"
-            if freshen and os.path.exists(poldek_idx) and os.path.exists(repodata_idx) \
-                and not os.path.getmtime(comps_file) > os.path.getmtime(repodata_idx) \
-                and not os.path.getmtime(poldek_idx) > os.path.getmtime(repodata_idx):
-                print("repodata indexes already fresh")
-                continue
-            print(f'{"" if quiet else "time"} {yum} --cachedir={cachedir}-{arch} {archdir}/RPMS')
-            run(f'{tree}/{arch}: createrepo_c', f'{"" if quiet else "time"} {yum} --cachedir={cachedir}-{arch} {archdir}/RPMS')
-            if arch != 'noarch' and config.separate_debuginfo:
-                run(f'{tree}/{arch}: createrepo_c', f'{"" if quiet else "time"} {yum} --cachedir={cachedir}-{arch} {archdir}/debuginfo')
-
-for tree in trees:
-    ftpio.unlock(tree)
+            build(tree, arch)
+finally:
+    # ftpiod drops a lock whoever asks, so only ours
+    for tree in locked:
+        ftpio.unlock(tree)
 
 for failure in failed:
     print(f"ERR: {failure}", file=sys.stderr)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/9da94db07ea316d05f5466d10ac4e10519ad6d46



More information about the pld-cvs-commit mailing list