remove duplicated code
Validate Operations / validate-operations (push) Has been cancelled

quieter validation scripts (with optional verbose flag)
This commit is contained in:
NiccoloN
2026-05-11 15:52:26 +02:00
parent 5ff364027b
commit 57f0cca8c0
4 changed files with 69 additions and 644 deletions
+23 -8
View File
@@ -16,7 +16,7 @@ def _read_chunk(fd, treat_eio_as_eof=False):
raise
def _stream_output(fd, process, reporter, treat_eio_as_eof=False):
def _stream_output(fd, process, reporter, treat_eio_as_eof=False, stream_output=True):
selector = selectors.DefaultSelector()
recent_output = bytearray()
captured_output = bytearray()
@@ -32,19 +32,22 @@ def _stream_output(fd, process, reporter, treat_eio_as_eof=False):
os.close(key.fileobj)
continue
reporter._clear()
os.write(1, data)
reporter._render()
if stream_output:
reporter._clear()
os.write(1, data)
reporter._render()
captured_output.extend(data)
recent_output.extend(data)
if len(recent_output) > MAX_ERROR_OUTPUT_BYTES:
del recent_output[:-MAX_ERROR_OUTPUT_BYTES]
if stream_output:
recent_output.extend(data)
if len(recent_output) > MAX_ERROR_OUTPUT_BYTES:
del recent_output[:-MAX_ERROR_OUTPUT_BYTES]
finally:
selector.close()
return_code = process.wait()
if return_code != 0:
raise subprocess.CalledProcessError(return_code, process.args, output=bytes(recent_output))
error_output = captured_output if not stream_output else recent_output
raise subprocess.CalledProcessError(return_code, process.args, output=bytes(error_output))
return bytes(captured_output)
@@ -62,6 +65,18 @@ def run_command_with_reporter(cmd, cwd=None, reporter=None, capture_output=False
subprocess.run(cmd, cwd=cwd, check=True)
return None
stream_output = bool(getattr(reporter, "verbose", False))
if not stream_output:
process = subprocess.Popen(
cmd,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
assert process.stdout is not None
output = _stream_output(process.stdout.fileno(), process, reporter, stream_output=False)
return output.decode("utf-8", errors="replace") if capture_output else None
try:
master_fd, slave_fd = pty.openpty()
except OSError: