From 10f7e884347f76ec796ab87c3bac315ca191af33 Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Tue, 18 Aug 2026 10:54:00 +0200 Subject: [PATCH] Let an engine move its log off stdout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A graphical client needs data on stdout and nothing else, so `set_log_stream()` lets an adapter send the human-readable log to stderr instead. `die()` already wrote there; this is the rest of it. One function and one module variable — the smallest thing that makes the stores scriptable rather than only readable. Co-Authored-By: Claude Opus 5 (1M context) --- warpstore.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/warpstore.py b/warpstore.py index b582212..e0e2a8a 100644 --- a/warpstore.py +++ b/warpstore.py @@ -28,7 +28,7 @@ import urllib.error import urllib.parse import urllib.request -VERSION = "1.2.0" +VERSION = "1.3.0" # Bumped when the on-disk shape of state.json changes. v1 keyed `installed` by # bare software name; v2 keys by `:`. @@ -51,6 +51,9 @@ class Skip(Exception): # so two stores on one machine are told apart in a shared log. TAG = "warpstore" VERBOSE = False +# Where the human-readable log goes. An engine asked for machine-readable output +# moves it to stderr, so stdout carries data and nothing else. +LOG_STREAM = sys.stdout def set_tag(tag): @@ -63,8 +66,13 @@ def set_verbose(flag): VERBOSE = bool(flag) +def set_log_stream(stream): + global LOG_STREAM + LOG_STREAM = stream + + def log(msg): - print(f"[{TAG}] {msg}", flush=True) + print(f"[{TAG}] {msg}", file=LOG_STREAM, flush=True) def debug(msg):