label listed updates in text output
This commit is contained in:
parent
943af1a316
commit
22a18a2069
@ -112,7 +112,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
def insert(self, text, iter):
|
||||
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:
|
||||
do_run = True
|
||||
elif not self.thread.is_alive():
|
||||
@ -123,7 +123,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
if do_run:
|
||||
self.thread = threading.Thread(
|
||||
target=self.run,
|
||||
args=(args, env,))
|
||||
args=(args, env, prefix,))
|
||||
|
||||
self.thread.start()
|
||||
|
||||
@ -137,6 +137,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
ignore_stderr=False,
|
||||
output_msg=None,
|
||||
empty_msg=None,
|
||||
prefix=None,
|
||||
env={},
|
||||
clear=True
|
||||
):
|
||||
@ -154,9 +155,15 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
"INFO",
|
||||
"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(
|
||||
args,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -175,7 +182,10 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
|
||||
if data:
|
||||
if key.fileobj is p.stdout:
|
||||
if prefix is None:
|
||||
self.stdout_queue.put(data)
|
||||
else:
|
||||
self.stdout_queue.put(prefix + " " + data)
|
||||
else:
|
||||
self.stderr_queue.put(data)
|
||||
|
||||
@ -222,7 +232,8 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
args,
|
||||
ignore_stderr=True,
|
||||
clear=clear,
|
||||
output_msg="Found the following package upgrades:",
|
||||
prefix="UPDATE",
|
||||
output_msg="Done listing available upgrades.",
|
||||
empty_msg="No package upgrades found."
|
||||
)
|
||||
|
||||
@ -238,16 +249,7 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
def on_quit(self, *args):
|
||||
self.application.quit()
|
||||
|
||||
def update_buffer(self):
|
||||
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))
|
||||
def process_exit(self, exit_code, empty_msg=None, output_msg=None):
|
||||
self.thread.join()
|
||||
|
||||
if exit_code != 0:
|
||||
@ -262,6 +264,25 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
|
||||
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:
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user