aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2024-02-14 19:51:41 +0100
committerMatěj Cepl <mcepl@cepl.eu>2024-02-14 19:51:41 +0100
commit6ca542805ba3b7731cba91b1ab3a057225de204d (patch)
treedf9f7888b6ed5b98bc1a1ac0fd12a1b837f1f079
parent48dc060d213f60b3579a31ead7e686fdabafc8c2 (diff)
downloadosc-fast-export-master.tar.gz
Actually capture stderr and show it in case of failure.HEADmaster
Fixes: gb#699d848
-rwxr-xr-xosc_fast_export.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/osc_fast_export.py b/osc_fast_export.py
index d0e693b..d6cfeb3 100755
--- a/osc_fast_export.py
+++ b/osc_fast_export.py
@@ -7,17 +7,19 @@ from datetime import datetime
import logging
import os.path
import pathlib
-import subprocess
+from subprocess import CalledProcessError, PIPE, run
import sys
from typing import Dict, List
import xml.etree.ElementTree as ET
-logging.basicConfig(format="%(levelname)s:%(funcName)s:%(message)s", level=logging.INFO)
+logging.basicConfig(format="%(levelname)s:%(funcName)s:%(message)s",
+ level=logging.INFO)
log = logging.getLogger("osc_fast_export")
NULL = open(os.devnull, "wb")
+
# For reading section-less config files
# https://stackoverflow.com/a/2819788/164233
def FakeSecHead(fp):
@@ -49,12 +51,14 @@ def get_authors() -> Dict[str, str]:
def osc_log() -> List[LogEntry]:
try:
- log_str = subprocess.run(
- ["osc", "log", "--xml"], check=True, text=True, stdout=subprocess.PIPE
- ).stdout
- except subprocess.CalledProcessError as exc:
- raise RuntimeError(f"Cannot collect log of the package!") from exc
-
+ log_pid = run(["osc", "log", "--xml"], check=True, text=True,
+ stdout=PIPE, stderr=PIPE
+ )
+ except CalledProcessError as exc:
+ raise RuntimeError(
+ f"Cannot collect log of the package!\nReported issue was:\n{log_pid.stderr}") from exc
+
+ log_str = log_pid.stdout
tree = ET.fromstring(log_str)
log_list = [
LogEntry(
@@ -72,12 +76,18 @@ def osc_log() -> List[LogEntry]:
def checkout_revision(rev: int):
try:
- subprocess.check_call(
- ["osc", "up", "-r", f"{rev}"], stdout=NULL, stderr=subprocess.PIPE
+ osc_pid = run(
+ ["osc", "up", "-r", f"{rev}"], stdout=PIPE, stderr=PIPE, check=True
)
- subprocess.check_call(["osc", "clean"], stdout=NULL, stderr=subprocess.PIPE)
- except subprocess.CalledProcessError as exc:
- raise RuntimeError(f"Cannot checkout revision {rev}!") from exc
+ except CalledProcessError as exc:
+ raise RuntimeError(
+ f"Cannot checkout revision {rev}!\nReported issue was:\n{osc_pid.stderr}") from exc
+
+ try:
+ osc_pid = run(["osc", "clean"], stdout=PIPE, stderr=PIPE, check=True)
+ except CalledProcessError as exc:
+ raise RuntimeError(
+ f"Cannot clean checkout!\nReported issue was:\n{osc_pid.stderr}") from exc
def print_export(entry: LogEntry, authors: Dict[str, str]) -> int:
@@ -116,7 +126,8 @@ def print_export(entry: LogEntry, authors: Dict[str, str]) -> int:
dt = inf.read()
print(f"data {len(dt)}")
sys.stdout.flush()
- with os.fdopen(sys.stdout.fileno(), "wb", closefd=False) as stdout:
+ with os.fdopen(sys.stdout.fileno(), "wb",
+ closefd=False) as stdout:
stdout.write(dt)
stdout.flush()
print("")