[projects/pld-builder.new] file_sender: report each queue's own problems
arekm
arekm at pld-linux.org
Mon Oct 26 17:16:41 CET 2026
commit dd03b24f0f6a84f1c4c891bce1c6ff1f5e82858d
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Oct 24 11:33:53 2026 +0200
file_sender: report each queue's own problems
The problems dict was never cleared, so each mail repeated the earlier
queues' failures.
PLD_Builder/file_sender.py | 83 ++++++++++++++++++++--------------------------
1 file changed, 36 insertions(+), 47 deletions(-)
---
diff --git a/PLD_Builder/file_sender.py b/PLD_Builder/file_sender.py
index 5dd2db9..51e13c1 100644
--- a/PLD_Builder/file_sender.py
+++ b/PLD_Builder/file_sender.py
@@ -5,8 +5,7 @@ import re
import os
import time
import shutil
-import sys
-import traceback
+import subprocess
import urllib.request
from config import config, init_conf
import mailer
@@ -35,22 +34,23 @@ def read_name_val(file):
f.close()
return None
+# the senders return None on success, otherwise a description of the problem
+
+def run_sender(cmd):
+ p = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, text=True, errors="replace", check=False)
+ if p.returncode:
+ return p.stdout or f"{cmd} failed with exit code {p.returncode}"
+ return None
+
def scp_file(src, target):
- f = os.popen("scp -v -B %s %s 2>&1 < /dev/null" % (src, target))
- p = f.read()
- ret = f.close()
- if ret:
- problems[src] = p
- return ret
+ return run_sender("scp -v -B %s %s 2>&1 < /dev/null" % (src, target))
def copy_file(src, target):
try:
shutil.copyfile(src, target)
- return 0
- except:
- exctype, value = sys.exc_info()[:2]
- problems[src] = "cannot copy file: %s" % traceback.format_exception_only(exctype, value)
- return 1
+ except OSError as e:
+ return f"cannot copy file: {e}"
+ return None
def rsync_file(src, target, host):
p = open(path.rsync_password_file, "r")
@@ -65,23 +65,13 @@ def rsync_file(src, target, host):
# password, it opens /dev/tty and still asks if password is needed and
# missing, therefore we always set RSYNC_PASSWORD env var
os.environ["RSYNC_PASSWORD"] = password
- rsync = "rsync --verbose --archive --timeout=360 --contimeout=360"
- f = os.popen("%s %s %s 2>&1" % (rsync, src, target))
- p = f.read()
- ret = f.close()
- if ret:
- problems[src] = p
- del os.environ["RSYNC_PASSWORD"];
- return ret
+ try:
+ return run_sender(f"rsync --verbose --archive --timeout=360 --contimeout=360 {src} {target} 2>&1")
+ finally:
+ del os.environ["RSYNC_PASSWORD"]
def rsync_ssh_file(src, target):
- rsync = "rsync --verbose --archive --timeout=360 -e ssh"
- f = os.popen("%s %s %s 2>&1 < /dev/null" % (rsync, src, target))
- p = f.read()
- ret = f.close()
- if ret:
- problems[src] = p
- return ret
+ return run_sender(f"rsync --verbose --archive --timeout=360 -e ssh {src} {target} 2>&1 < /dev/null")
def post_file(src, url):
try:
@@ -93,33 +83,32 @@ def post_file(src, url):
f = urllib.request.urlopen(req)
f.close()
except Exception as e:
- problems[src] = e
- return e
- return 0
+ # never empty: an empty problem would count as success
+ return str(e) or repr(e)
+ return None
def send_file(src, target):
try:
log.notice("sending %s to %s (size %d bytes)" % (src, target, os.stat(src).st_size))
m = re.match(r'rsync://([^/]+)/.*', target)
if m:
- return not rsync_file(src, target, host = m.group(1))
+ return rsync_file(src, target, host = m.group(1))
if target != "" and target[0] == '/':
- return not copy_file(src, target)
+ return copy_file(src, target)
m = re.match(r'scp://([^@:]+@[^/:]+)(:|)(.*)', target)
if m:
- return not scp_file(src, m.group(1) + ":" + m.group(3))
+ return scp_file(src, m.group(1) + ":" + m.group(3))
m = re.match(r'ssh\+rsync://([^@:]+@[^/:]+)(:|)(.*)', target)
if m:
- return not rsync_ssh_file(src, m.group(1) + ":" + m.group(3))
+ return rsync_ssh_file(src, m.group(1) + ":" + m.group(3))
m = re.match(r'(http|https)://.*', target)
if m:
- return not post_file(src, target)
+ return post_file(src, target)
log.alert("unsupported protocol: %s" % target)
except OSError as e:
- problems[src] = e
log.error("send_file(%s, %s): %s" % (src, target, e))
- return False
- return True
+ return str(e) or repr(e)
+ return None
def maybe_flush_queue(dir):
retry_delay = 0
@@ -162,23 +151,25 @@ def flush_queue(dir):
return rc
q.sort(key=util.cmp_to_key(mycmp))
- error = None
+ problems = {}
# copy of q
remaining = q[:]
for d in q:
- if not send_file(d['_file'], d['Target']):
- error = d
+ err = send_file(d['_file'], d['Target'])
+ if err:
+ problems[d['_file']] = err
continue
if os.access(d['_file'] + ".info", os.F_OK):
- if not send_file(d['_file'] + ".info", d['Target'] + ".info"):
- error = d
+ err = send_file(d['_file'] + ".info", d['Target'] + ".info")
+ if err:
+ problems[d['_file'] + ".info"] = err
continue
os.unlink(d['_file'] + ".info")
os.unlink(d['_file'])
os.unlink(d['_desc'])
remaining.remove(d)
- if error != None:
+ if problems:
emails = {}
emails[config.admin_email] = 1
pr = ""
@@ -200,8 +191,6 @@ def flush_queue(dir):
return 0
-problems = {}
-
def main():
if lock.lock("sending-files", non_block = 1) == None:
return
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/ce9feb3c796ed049b6dd260a50d94d80feb1656d
More information about the pld-cvs-commit
mailing list