label listed updates in text output

This commit is contained in:
Tilman Kranz 2023-07-21 14:02:12 +02:00
parent 943af1a316
commit 22a18a2069

View File

@ -112,7 +112,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
def insert(self, text, iter): def insert(self, text, iter):
self.buffer.insert(iter, text + "\n") self.buffer.insert(iter, text + "\n")
def run_thread(self, args, env): def run_thread(self, args, env, prefix=None):
if self.thread is None: if self.thread is None:
do_run = True do_run = True
elif not self.thread.is_alive(): elif not self.thread.is_alive():
@ -123,7 +123,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
if do_run: if do_run:
self.thread = threading.Thread( self.thread = threading.Thread(
target=self.run, target=self.run,
args=(args, env,)) args=(args, env, prefix,))
self.thread.start() self.thread.start()
@ -137,6 +137,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
ignore_stderr=False, ignore_stderr=False,
output_msg=None, output_msg=None,
empty_msg=None, empty_msg=None,
prefix=None,
env={}, env={},
clear=True clear=True
): ):
@ -154,9 +155,15 @@ class UpdateWindow(Gtk.ApplicationWindow):
"INFO", "INFO",
"Running command \"%s\" ..." % " ".join(args)) "Running command \"%s\" ..." % " ".join(args))
GLib.timeout_add(250, self.run_thread, args, env) GLib.timeout_add(
250,
self.run_thread,
args,
env,
prefix
)
def run(self, args, env={}): def run(self, args, env={}, prefix=None):
p = subprocess.Popen( p = subprocess.Popen(
args, args,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@ -175,7 +182,10 @@ class UpdateWindow(Gtk.ApplicationWindow):
if data: if data:
if key.fileobj is p.stdout: if key.fileobj is p.stdout:
if prefix is None:
self.stdout_queue.put(data) self.stdout_queue.put(data)
else:
self.stdout_queue.put(prefix + " " + data)
else: else:
self.stderr_queue.put(data) self.stderr_queue.put(data)
@ -222,7 +232,8 @@ class UpdateWindow(Gtk.ApplicationWindow):
args, args,
ignore_stderr=True, ignore_stderr=True,
clear=clear, clear=clear,
output_msg="Found the following package upgrades:", prefix="UPDATE",
output_msg="Done listing available upgrades.",
empty_msg="No package upgrades found." empty_msg="No package upgrades found."
) )
@ -238,16 +249,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
def on_quit(self, *args): def on_quit(self, *args):
self.application.quit() self.application.quit()
def update_buffer(self): def process_exit(self, exit_code, empty_msg=None, output_msg=None):
try:
text = self.stdout_queue.get(block=False)
match = re.fullmatch(r'EXIT (\d+)', text)
if match is None:
self.stdout += text
self.append_mesg("STDOUT", text)
else:
exit_code = int(match.group(1))
self.thread.join() self.thread.join()
if exit_code != 0: if exit_code != 0:
@ -262,6 +264,25 @@ class UpdateWindow(Gtk.ApplicationWindow):
self.unlock() self.unlock()
def update_buffer(self):
try:
text = self.stdout_queue.get(block=False)
match = re.fullmatch(r'(EXIT|UPDATE) (.*)', text)
if match is None:
self.stdout += text
self.append_mesg("STDOUT", text)
elif match.group(1) == 'EXIT':
exit_code = int(match.group(2))
self.process_exit(exit_code)
elif match.group(1) == 'UPDATE':
text = match.group(2)
self.stdout += text
self.append_mesg("UPDATE", text)
else:
self.stdout += text
self.append_mesg("UPDATE", text)
except queue.Empty: except queue.Empty:
pass pass