From 0caa892f25c467bc314d9dbc18434a1bc05146a3 Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Thu, 20 Jul 2023 08:02:45 +0200 Subject: [PATCH] improved output formatting --- bin/simple-apt-update | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/bin/simple-apt-update b/bin/simple-apt-update index 831ee90..7170658 100755 --- a/bin/simple-apt-update +++ b/bin/simple-apt-update @@ -112,9 +112,12 @@ class UpdateWindow(Gtk.ApplicationWindow): self.buffer.insert(iter, text + "\n") def execute(self, args, ignore_stderr=False, output_msg=None, - empty_msg=None, env={}): + empty_msg=None, env={}, clear=True): self.lock() - self.clear() + + if clear: + self.clear() + self.output_msg = output_msg self.empty_msg = empty_msg self.ignore_stderr = ignore_stderr @@ -176,19 +179,20 @@ class UpdateWindow(Gtk.ApplicationWindow): def on_upgrade(self, *args): self.upgrade() - def update(self): + def update(self, clear=True): args = ['/usr/bin/apt-get', '-y', 'update'] env = {'DEBIAN_FRONTEND': 'noninteractive'} - self.execute(args, env=env) + self.execute(args, env=env, clear=clear) def on_update(self, *args): self.update() - def list(self): + def list(self, clear=True): args = ['/usr/bin/apt', '-qq', 'list', '--upgradable'] self.execute( args, ignore_stderr=True, + clear=clear, output_msg="Found the following package upgrades:", empty_msg="Currently there are no available package upgrades.") @@ -201,13 +205,12 @@ class UpdateWindow(Gtk.ApplicationWindow): def update_buffer(self): try: text = self.stdout_queue.get(block=False) - - self.stdout += text - self.append_mesg("STDOUT", text) - match = re.fullmatch(r'EXIT (\d+)', text) - if match is not None: + if match is None: + self.stdout += text + self.append_mesg("STDOUT", text) + else: exit_code = int(match.group(1)) if exit_code != 0: @@ -337,6 +340,8 @@ class SimpleAptUpdate(Gtk.Application): self.window.present() self.window.show_all() + self.window.update() + self.window.list(clear=False) ##