[projects/pld-builder.new] chroot: run commands through subprocess

arekm arekm at pld-linux.org
Sun Nov 15 01:57:46 CET 2026


commit 4111fc902343f35312d976feb65cb844ea27d284
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sat Nov 14 22:50:40 2026 +0100

    chroot: run commands through subprocess
    
    So that a caller can wait on a command for a while, which os.popen() does
    not allow. The same exit codes and log; logstdout, which nothing passed,
    is gone.

 PLD_Builder/chroot.py | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
---
diff --git a/PLD_Builder/chroot.py b/PLD_Builder/chroot.py
index a093136..4fa0b99 100644
--- a/PLD_Builder/chroot.py
+++ b/PLD_Builder/chroot.py
@@ -1,6 +1,5 @@
 # vi: ts=8 sts=4 sw=4 et
 
-import os
 import re
 import shutil
 import subprocess
@@ -50,24 +49,12 @@ def popen(cmd, user = "builder", mode = "r", encoding = None, nonet=True):
     p = subprocess.Popen(command(cmd, user, nonet=nonet), shell=True, stdin=subprocess.PIPE, close_fds=True, encoding=encoding)
     return Pipe(p, p.stdin)
 
-def run(cmd, user = "builder", logfile = None, logstdout = None, nonet=True):
+def run(cmd, user = "builder", logfile = None, nonet=True):
+    """Run cmd in the chroot as user, its output appended to logfile; the exit code, negative for a signal"""
     c = command(cmd, user, nostdin=True, nonet=nonet)
     if logfile != None:
-        if logstdout != None:
-            c = f"{c} 2>&1 | /usr/bin/tee -a {logfile}"
-        else:
-            c = f"{c} >> {logfile} 2>&1"
-    f = os.popen(c)
-    if logstdout != None:
-        for l in f:
-            logstdout.write(l)
-    else:
-        f.read()
-    r = f.close()
-    if r == None:
-        return 0
-    # close() gives the exit code shifted left by 8 bits, negative for a signal
-    return r >> 8
+        c = f"{c} >> {logfile} 2>&1"
+    return subprocess.run(c, check=False, shell=True, stdout=subprocess.DEVNULL).returncode
 
 def cp(file, outfile, user="builder", rm=False):
     cmd = f"cat {file}"
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list