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):
|
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:
|
||||||
self.stdout_queue.put(data)
|
if prefix is None:
|
||||||
|
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,29 +249,39 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
|||||||
def on_quit(self, *args):
|
def on_quit(self, *args):
|
||||||
self.application.quit()
|
self.application.quit()
|
||||||
|
|
||||||
|
def process_exit(self, exit_code, empty_msg=None, output_msg=None):
|
||||||
|
self.thread.join()
|
||||||
|
|
||||||
|
if exit_code != 0:
|
||||||
|
self.append_mesg(
|
||||||
|
"ERROR",
|
||||||
|
"Command exited with code %d" % exit_code
|
||||||
|
)
|
||||||
|
elif self.stdout == '' and self.empty_msg is not None:
|
||||||
|
self.append_mesg("INFO", self.empty_msg)
|
||||||
|
elif self.stdout != '' and self.output_msg is not None:
|
||||||
|
self.append_mesg("INFO", self.output_msg)
|
||||||
|
|
||||||
|
self.unlock()
|
||||||
|
|
||||||
def update_buffer(self):
|
def update_buffer(self):
|
||||||
try:
|
try:
|
||||||
text = self.stdout_queue.get(block=False)
|
text = self.stdout_queue.get(block=False)
|
||||||
match = re.fullmatch(r'EXIT (\d+)', text)
|
match = re.fullmatch(r'(EXIT|UPDATE) (.*)', text)
|
||||||
|
|
||||||
if match is None:
|
if match is None:
|
||||||
self.stdout += text
|
self.stdout += text
|
||||||
self.append_mesg("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:
|
else:
|
||||||
exit_code = int(match.group(1))
|
self.stdout += text
|
||||||
self.thread.join()
|
self.append_mesg("UPDATE", text)
|
||||||
|
|
||||||
if exit_code != 0:
|
|
||||||
self.append_mesg(
|
|
||||||
"ERROR",
|
|
||||||
"Command exited with code %d" % exit_code
|
|
||||||
)
|
|
||||||
elif self.stdout == '' and self.empty_msg is not None:
|
|
||||||
self.append_mesg("INFO", self.empty_msg)
|
|
||||||
elif self.stdout != '' and self.output_msg is not None:
|
|
||||||
self.append_mesg("INFO", self.output_msg)
|
|
||||||
|
|
||||||
self.unlock()
|
|
||||||
|
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user