aboutsummaryrefslogtreecommitdiffstats
path: root/osc_fast_export.py
diff options
context:
space:
mode:
Diffstat (limited to 'osc_fast_export.py')
-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("")