improved output formatting

This commit is contained in:
Tilman Kranz 2023-07-20 08:02:45 +02:00
parent 5e8c57937f
commit 0caa892f25

View File

@ -112,9 +112,12 @@ class UpdateWindow(Gtk.ApplicationWindow):
self.buffer.insert(iter, text + "\n") self.buffer.insert(iter, text + "\n")
def execute(self, args, ignore_stderr=False, output_msg=None, def execute(self, args, ignore_stderr=False, output_msg=None,
empty_msg=None, env={}): empty_msg=None, env={}, clear=True):
self.lock() self.lock()
self.clear()
if clear:
self.clear()
self.output_msg = output_msg self.output_msg = output_msg
self.empty_msg = empty_msg self.empty_msg = empty_msg
self.ignore_stderr = ignore_stderr self.ignore_stderr = ignore_stderr
@ -176,19 +179,20 @@ class UpdateWindow(Gtk.ApplicationWindow):
def on_upgrade(self, *args): def on_upgrade(self, *args):
self.upgrade() self.upgrade()
def update(self): def update(self, clear=True):
args = ['/usr/bin/apt-get', '-y', 'update'] args = ['/usr/bin/apt-get', '-y', 'update']
env = {'DEBIAN_FRONTEND': 'noninteractive'} env = {'DEBIAN_FRONTEND': 'noninteractive'}
self.execute(args, env=env) self.execute(args, env=env, clear=clear)
def on_update(self, *args): def on_update(self, *args):
self.update() self.update()
def list(self): def list(self, clear=True):
args = ['/usr/bin/apt', '-qq', 'list', '--upgradable'] args = ['/usr/bin/apt', '-qq', 'list', '--upgradable']
self.execute( self.execute(
args, args,
ignore_stderr=True, ignore_stderr=True,
clear=clear,
output_msg="Found the following package upgrades:", output_msg="Found the following package upgrades:",
empty_msg="Currently there are no available package upgrades.") empty_msg="Currently there are no available package upgrades.")
@ -201,13 +205,12 @@ class UpdateWindow(Gtk.ApplicationWindow):
def update_buffer(self): def update_buffer(self):
try: try:
text = self.stdout_queue.get(block=False) text = self.stdout_queue.get(block=False)
self.stdout += text
self.append_mesg("STDOUT", text)
match = re.fullmatch(r'EXIT (\d+)', 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)) exit_code = int(match.group(1))
if exit_code != 0: if exit_code != 0:
@ -337,6 +340,8 @@ class SimpleAptUpdate(Gtk.Application):
self.window.present() self.window.present()
self.window.show_all() self.window.show_all()
self.window.update()
self.window.list(clear=False)
## ##