imrpoved message formatting and cleanup
This commit is contained in:
parent
8aed22de69
commit
0f02715bac
@ -1,16 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
# simple-apt-update - A GUI for basic tasks of package management using apt
|
||||
# Copyright (C) 2023 Tilman Kranz <t.kranz@tk-sls.de>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
##
|
||||
# Imports
|
||||
|
||||
import re
|
||||
import queue
|
||||
import threading
|
||||
import gi
|
||||
import html
|
||||
import logging
|
||||
import os
|
||||
import queue
|
||||
import re
|
||||
import selectors
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
|
||||
gi.require_version('Gdk', '3.0')
|
||||
gi.require_version('Gtk', '3.0')
|
||||
@ -21,12 +39,6 @@ except ImportError:
|
||||
logging.error("Could not import Gio")
|
||||
sys.exit(1)
|
||||
|
||||
# try:
|
||||
# from gi.repository import GObject
|
||||
# except ImportError:
|
||||
# logging.error("Could not import GObject")
|
||||
# sys.exit(1)
|
||||
|
||||
try:
|
||||
from gi.repository import GLib
|
||||
except ImportError:
|
||||
@ -40,6 +52,9 @@ except ImportError:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
##
|
||||
# Classes
|
||||
|
||||
class UpdateWindow(Gtk.ApplicationWindow):
|
||||
def clear(self):
|
||||
self.buffer.set_text("")
|
||||
@ -100,6 +115,11 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
empty_msg=None, env={}):
|
||||
self.lock()
|
||||
self.clear()
|
||||
self.output_msg = output_msg
|
||||
self.empty_msg = empty_msg
|
||||
self.ignore_stderr = ignore_stderr
|
||||
self.stdout = ''
|
||||
self.stderr = ''
|
||||
self.prepend_mesg(
|
||||
"INFO",
|
||||
"Running command \"%s\" ..." % " ".join(args))
|
||||
@ -181,14 +201,23 @@ 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:
|
||||
exit_code = int(match.group(1))
|
||||
|
||||
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.empty_msg)
|
||||
|
||||
self.unlock()
|
||||
|
||||
@ -197,6 +226,10 @@ class UpdateWindow(Gtk.ApplicationWindow):
|
||||
|
||||
try:
|
||||
text = self.stderr_queue.get(block=False)
|
||||
|
||||
self.stderr += text
|
||||
|
||||
if not self.ignore_stderr:
|
||||
self.append_mesg("STDERR", text)
|
||||
except queue.Empty:
|
||||
pass
|
||||
@ -306,6 +339,9 @@ class SimpleAptUpdate(Gtk.Application):
|
||||
self.window.show_all()
|
||||
|
||||
|
||||
##
|
||||
# Main Program
|
||||
|
||||
def main():
|
||||
application = SimpleAptUpdate()
|
||||
exit_status = application.run()
|
||||
|
Loading…
Reference in New Issue
Block a user