From 6b424dfdf0e8ca0eb882914d47b5246eaf4ee56f Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Tue, 18 Jul 2023 16:39:45 +0200 Subject: [PATCH] do not use python-apt --- bin/simple-apt-update | 126 +++++++++++++----------------------------- 1 file changed, 37 insertions(+), 89 deletions(-) diff --git a/bin/simple-apt-update b/bin/simple-apt-update index 055e77e..432649b 100755 --- a/bin/simple-apt-update +++ b/bin/simple-apt-update @@ -4,8 +4,7 @@ import subprocess import selectors import html import gi -import apt -import apt.progress +import os gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') @@ -21,75 +20,6 @@ except ImportError: print("ERROR: Could not import Gtk") -class AptFetchProgress(apt.progress.base.AcquireProgress): - def __init__(self, update_window): - super().__init__() - self.update_window = update_window - - def done(self, item): - super().done(item) - self.update_window.append("Done fetching package updates.") - - def fail(self, item): - super().fail(item) - self.update_window.append( - "ERROR: The following item could not be downloaded: %s" % item.uri) - - def fetch(self, item): - super().fetch(item) - self.update_window.append( - "INFO: The following item was downloaded: %s" % item.uri) - - def ims_hit(self, item): - super().ims_hit(item) - self.update_window.append( - "INFO: The following item was found in the cache: %s" % item.uri) - - def media_change(self, str, drive): - super().media_change(str, drive) - self.update_window.append( - "ERROR: Media changes are not supported (str=%s, drive=%s)" % - (str, drive)) - return False - - def pulse(self, owner): - super().pulse(owner) - return True - - -class AptInstallProgress(apt.progress.base.InstallProgress): - def __init__(self, update_window): - super().__init__() - self.update_window = update_window - self.count = 0 - - def conffile(self, current, new): - super().conffile(current, new) - self.update_window.append_mesg( - "WARNING", - "The following configuration file was not modified: %s" % - current) - - def error(self, pkg, errormsg): - super().error(pkg, errormsg) - self.update_window.append_mesg( - "ERROR", - "Installation of package %s failed: %s" % (pkg, errormsg)) - - def processing(self, pkg, stage): - super().error(pkg, stage) - self.update_window.append_mesg( - "INFO", - "Processing package %s, stage %s" % (pkg, stage)) - - def dpkg_status_change(self, pkg, status): - super().dpkg_status_change(pkg, status) - print("dpkg_status_change: pkg=%s status=%s" % (pkg, status)) - self.update_window.append_mesg( - "INFO", - "Package %s is now has status %s" % (pkg, status)) - - class UpdateWindow(Gtk.ApplicationWindow): def clear(self): self.buffer.set_text("") @@ -146,9 +76,11 @@ class UpdateWindow(Gtk.ApplicationWindow): def insert(self, text, iter): self.buffer.insert(iter, text + "\n") - def run(self, args, ignore_stderr=False, output_msg=None, empty_msg=None): + def run(self, args, ignore_stderr=False, output_msg=None, + empty_msg=None, env={}): p = subprocess.Popen( - args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False) + args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, + env=dict(os.environ, **env)) sel = selectors.DefaultSelector() sel.register(p.stdout, selectors.EVENT_READ) @@ -163,10 +95,10 @@ class UpdateWindow(Gtk.ApplicationWindow): if data: if key.fileobj is p.stdout: - self.append(data) + self.append_mesg("STDOUT", data) output = True elif not ignore_stderr: - self.append(data) + self.append_mesg("STDERR", data) exit_code = p.poll() @@ -181,23 +113,43 @@ class UpdateWindow(Gtk.ApplicationWindow): done = True break - if not error: + if error: + return False + else: if output: if output_msg is not None: self.prepend_mesg("INFO", output_msg) elif empty_msg is not None: self.append_mesg("INFO", empty_msg) + return True + + def lock(self): + self.update_button.set_sensitive(False) + self.upgrade_button.set_sensitive(False) + self.list_button.set_sensitive(False) + + def unlock(self): + self.update_button.set_sensitive(True) + self.upgrade_button.set_sensitive(True) + self.list_button.set_sensitive(True) + def on_upgrade(self, *args): - self.cache.open(None) - self.cache.upgrade(True) - self.cache.commit(AptFetchProgress(self), AptInstallProgress(self)) + self.clear() + self.run( + ['/usr/bin/apt-get', '-y', 'full-upgrade'], + env={'DEBIAN_FRONTEND': 'noninteractive'}) + self.append_mesg("INFO", "Upgrade done.") def on_update(self, *args): - self.cache.update() + self.clear() + self.run( + ['/usr/bin/apt-get', '-y', 'update'], + env={'DEBIAN_FRONTEND': 'noninteractive'}) self.append_mesg("INFO", "The package cache was updated.") def on_list(self, *args): + self.clear() self.run( ['/usr/bin/apt', '-qq', 'list', '--upgradable'], ignore_stderr=True, @@ -208,7 +160,9 @@ class UpdateWindow(Gtk.ApplicationWindow): self.app.quit() def __init__(self, app): - super(UpdateWindow, self).__init__(application=app, title="Simple APT Update") + super(UpdateWindow, self).__init__( + application=app, + title="Simple APT Update") self.app = app self.init_ui() @@ -255,19 +209,13 @@ class UpdateWindow(Gtk.ApplicationWindow): self.scrolledwindow.add(text_view) hbox.pack_start(self.scrolledwindow, True, True, 0) - self.cache = apt.Cache() - self.cache.update() - self.append_mesg("INFO", "The package cache was updated.") - - self.on_update() - self.clear() - self.on_list() - def on_activate(app): win = UpdateWindow(app) win.present() win.show_all() + win.on_update() + win.on_list() app = Gtk.Application(application_id='org.linuxfoo.SimpleAptUpdate')