From 6e9de605dba5a555757bf8f4877f6b7f94cf20f2 Mon Sep 17 00:00:00 2001 From: ericbsd Date: Tue, 25 Feb 2025 22:21:05 -0400 Subject: [PATCH 1/3] Reverted the removal of force upgrade and improved some code. --- setup.py | 2 +- update_station/backend.py | 133 +++++++++++++------------ update_station/data.py | 2 - update_station/dialog.py | 154 ++++++++++++++-------------- update_station/frontend.py | 199 ++++++++++++------------------------- 5 files changed, 216 insertions(+), 274 deletions(-) diff --git a/setup.py b/setup.py index 09a442b..c7aff9e 100755 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ # to update i18n .mo files (and merge .pot file into .po files) run on Linux: # python setup.py build_i18n -m'' -__VERSION__ = '6.2' +__VERSION__ = '6.3' PROGRAM_VERSION = __VERSION__ prefix = sys.prefix diff --git a/update_station/backend.py b/update_station/backend.py index 50e0fe9..d1e3d14 100755 --- a/update_station/backend.py +++ b/update_station/backend.py @@ -33,7 +33,7 @@ def on_reboot(*args) -> None: Gtk.main_quit() -def get_detail() -> None: +def get_detail(*args) -> None: """ Get the details of the upgrade failure. :return: @@ -41,15 +41,6 @@ def get_detail() -> None: Popen(f'sudo -u {Data.username} xdg-open {Data.home}/update.failed', shell=True) -def get_packages_to_reinstall() -> list: - """ - Get packages to reinstall on kernel upgrade. - :return: The list of packages to reinstall. - """ - packages = read_file(f'../src/pkg_to_reinstall').replace('\n', ' ') - return run_command(f'pkg query "%n" {packages}').stdout.splitlines() - - def run_command(command: str, check: bool = False) -> CompletedProcess: """ Run a shell command and optionally check for errors. @@ -76,11 +67,7 @@ def check_for_update() -> bool: return False elif 'UPGRADED:' in upgrade_text: return True - elif ' INSTALLED:' in upgrade_text: - return True - elif 'REINSTALLED:' in upgrade_text: - return True - elif 'REMOVED:' in upgrade_text: + elif 'DOWNGRADED:' in upgrade_text: return True else: return False @@ -153,10 +140,42 @@ def get_pkg_upgrade(option: str = '') -> str: return upgrade_verbose +def get_packages_list_by_upgrade_type(upgrade_type: str, update_pkg: str, update_pkg_list: list) -> list: + """ + Get the list of packages by the upgrade type. + :param upgrade_type: The upgrade type: REMOVED, UPGRADED, INSTALLED, REINSTALLED, DOWNGRADED. + :param update_pkg: The upgrade data. + :param update_pkg_list: The list of the upgrade data. + :return: The list of packages. + """ + package_list = [] + stop = False + if f'{upgrade_type}:' in update_pkg: + for line in update_pkg_list: + if f'{upgrade_type}:' in line: + stop = True + elif stop is True and line == '': + break + elif stop is True: + package_list.append(line.strip()) + return package_list + def get_pkg_upgrade_data() -> dict: """ - Get the upgrade data from pkg. - :return: The upgrade data. + This function is used to get the upgrade data from pkg. + :return: Returns a dictionary with the following keys: + - system_upgrade: True if the system is upgrading else False. + - remove: The list of packages to remove. + - number_to_remove: The number of packages to remove. + - upgrade: The list of packages to upgrade. + - number_to_upgrade: The number of packages to upgrade. + - upgrade: The list of packages to upgrade. + - number_to_upgrade: The number of packages to upgrade. + - install: The list of packages to install. + - number_to_install: The number of packages to install. + - reinstall: The list of packages to reinstall. + - number_to_reinstall: The number of packages to reinstall. + - total_of_packages: The total number of packages to upgrade. """ option = '' system_upgrade = False @@ -166,54 +185,46 @@ def get_pkg_upgrade_data() -> dict: option = 'f' update_pkg = get_pkg_upgrade(option) update_pkg_list = update_pkg.splitlines() - pkg_to_remove = [] - pkg_to_upgrade = [] - pkg_to_install = [] - pkg_to_reinstall = [] - stop = False - if 'REMOVED:' in update_pkg: - for line in update_pkg_list: - if 'REMOVED:' in line: - stop = True - elif stop is True and line == '': - stop = False - break - elif stop is True: - pkg_to_remove.append(line.strip()) - if 'UPGRADED:' in update_pkg: - for line in update_pkg_list: - if 'UPGRADED:' in line: - stop = True - elif stop is True and line == '': - stop = False - break - elif stop is True: - pkg_to_upgrade.append(line.strip()) - if ' INSTALLED:' in update_pkg: - for line in update_pkg_list: - if ' INSTALLED:' in line: - stop = True - elif stop is True and line == '': - stop = False - break - elif stop is True: - pkg_to_install.append(line.strip()) - if 'REINSTALLED:' in update_pkg: - for line in update_pkg_list: - if 'REINSTALLED:' in line: - stop = True - elif stop is True and line == '': - break - elif stop is True: - pkg_to_reinstall.append(line.strip()) - pkg_dictionary = { + pkg_to_upgrade = get_packages_list_by_upgrade_type( + 'UPGRADED', update_pkg, update_pkg_list + ) + pkg_to_downgrade = get_packages_list_by_upgrade_type( + 'DOWNGRADED', update_pkg, update_pkg_list + ) + pkg_to_install = get_packages_list_by_upgrade_type( + ' INSTALLED', update_pkg, update_pkg_list + ) + pkg_to_reinstall = get_packages_list_by_upgrade_type( + 'REINSTALLED', update_pkg, update_pkg_list + ) + pkg_to_remove = get_packages_list_by_upgrade_type( + 'REMOVED', update_pkg, update_pkg_list + ) + total_of_packages = len(pkg_to_upgrade) + total_of_packages += (len(pkg_to_downgrade) + + len(pkg_to_install) + + len(pkg_to_reinstall) + + len(pkg_to_remove)) + return { 'system_upgrade': system_upgrade, - 'remove': pkg_to_remove, 'upgrade': pkg_to_upgrade, + 'number_to_upgrade': len(pkg_to_upgrade), + 'downgrade': pkg_to_downgrade, + 'number_to_downgrade': len(pkg_to_downgrade), 'install': pkg_to_install, - 'reinstall': pkg_to_reinstall + 'number_to_install': len(pkg_to_install), + 'reinstall': pkg_to_reinstall, + 'number_to_reinstall': len(pkg_to_reinstall), + 'remove': pkg_to_remove, + 'number_to_remove': len(pkg_to_remove), + 'total_of_packages': ( + len(pkg_to_upgrade) + + len(pkg_to_downgrade) + + len(pkg_to_install) + + len(pkg_to_reinstall) + + len(pkg_to_remove) + ) } - return pkg_dictionary def is_major_upgrade_available() -> bool: diff --git a/update_station/data.py b/update_station/data.py index 69546ad..7016f4f 100755 --- a/update_station/data.py +++ b/update_station/data.py @@ -19,7 +19,6 @@ class Data: second_update: Boolean that indicates if the update-station should do 2 update. stop_pkg_refreshing: Boolean that indicates if the update-station should stop refreshing the packages. system_tray: Object that contains the system tray of the update-station. - total_packages: Integer that indicates the total number of packages that are that will be updated. update_started: Boolean that indicates if the application has started updating the system. username: String that indicates the username of the user that is running the update-station. """ @@ -35,6 +34,5 @@ class Data: second_update: bool = False stop_pkg_refreshing: bool = False system_tray = None - total_packages: int = 0 update_started: bool = False username: str = os.environ.get('SUDO_USER') if 'SUDO_USER' in os.environ else getpass.getuser() diff --git a/update_station/dialog.py b/update_station/dialog.py index 7a3e9c0..eb80d79 100644 --- a/update_station/dialog.py +++ b/update_station/dialog.py @@ -30,7 +30,7 @@ def __init__(self): window.connect("delete-event", on_close, window) window.set_title(_("Update Failed")) window.set_default_icon_name('system-software-update') - v_box = Gtk.VBox(homogeneous=False, spacing=0) + v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) window.add(v_box) v_box.show() label = Gtk.Label() @@ -39,7 +39,7 @@ def __init__(self): label.set_markup(failed_text) v_box.set_border_width(5) v_box.pack_start(label, False, False, 5) - h_box = Gtk.HBox(homogeneous=False, spacing=0) + h_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=0) # hBox.set_border_width(5) v_box.pack_start(h_box, False, True, 5) h_box.show() @@ -67,14 +67,14 @@ def __init__(self): window.connect("destroy", on_close, window) window.set_title(_("Update Completed")) window.set_default_icon_name('system-software-update') - v_box = Gtk.VBox(homogeneous=False, spacing=0) + v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) window.add(v_box) v_box.show() reboot_text = _("The computer needs to restart to run on the updated software.") label = Gtk.Label(label=reboot_text) v_box.set_border_width(5) v_box.pack_start(label, False, False, 5) - h_box = Gtk.HBox(homogeneous=False, spacing=0) + h_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=0) # h_box.set_border_width(5) v_box.pack_start(h_box, False, True, 5) h_box.show() @@ -101,13 +101,13 @@ def __init__(self): window.connect("destroy", on_close, window) window.set_title(_("Update Completed")) window.set_default_icon_name('system-software-update') - v_box = Gtk.VBox(homogeneous=False, spacing=0) + v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, hhomogeneous=False, spacing=0) window.add(v_box) v_box.show() label = Gtk.Label(label=_("""All software on this system is up to date.""")) v_box.set_border_width(5) v_box.pack_start(label, False, False, 5) - h_box = Gtk.HBox(homogeneous=False, spacing=0) + h_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, hhomogeneous=False, spacing=0) # h_box.set_border_width(5) v_box.pack_start(h_box, False, True, 5) h_box.show() @@ -131,23 +131,23 @@ def __init__(self): window.set_border_width(8) window.connect("destroy", on_close, window) window.set_title(_("No Update Available")) - box1 = Gtk.VBox(homogeneous=False, spacing=0) - window.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + window.add(vbox1) + vbox1.show() + vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=10) + vbox2.set_border_width(10) + vbox1.pack_start(vbox2, True, True, 0) + vbox2.show() label = Gtk.Label(label=_("No update available. This system is up " "to date.")) - box2.pack_start(label, False, False, 0) - box2 = Gtk.HBox(homogeneous=False, spacing=10) - box2.set_border_width(5) - box1.pack_start(box2, False, True, 0) - box2.show() + vbox2.pack_start(label, False, False, 0) + hbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox1.set_border_width(5) + vbox1.pack_start(hbox1, False, True, 0) + hbox1.show() ok_button = Gtk.Button(label=_("Close")) ok_button.connect("clicked", on_close, window) - box2.pack_end(ok_button, False, False, 0) + hbox1.pack_end(ok_button, False, False, 0) window.show_all() @@ -165,22 +165,22 @@ def __init__(self): window.set_border_width(8) window.connect("destroy", on_close, window) window.set_title(_("Update Station already started")) - box1 = Gtk.VBox(homogeneous=False, spacing=0) - window.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + window.add(vbox1) + vbox1.show() + vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=10) + vbox2.set_border_width(10) + vbox1.pack_start(vbox2, True, True, 0) + vbox2.show() label = Gtk.Label(label=_("Update Station already open.")) - box2.pack_start(label, False, False, 0) - box2 = Gtk.HBox(homogeneous=False, spacing=10) - box2.set_border_width(5) - box1.pack_start(box2, False, True, 0) - box2.show() + vbox2.pack_start(label, False, False, 0) + hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox2.set_border_width(5) + vbox1.pack_start(hbox2, False, True, 0) + hbox2.show() ok_button = Gtk.Button(label=_("Close")) ok_button.connect("clicked", on_close, window) - box2.pack_end(ok_button, False, False, 0) + hbox2.pack_end(ok_button, False, False, 0) window.show_all() @@ -198,23 +198,23 @@ def __init__(self): window.set_border_width(8) window.connect("destroy", on_close, window) window.set_title(_("Server Unreachable")) - box1 = Gtk.VBox(homogeneous=False, spacing=0) - window.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + window.add(vbox1) + vbox1.show() + vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=10) + vbox2.set_border_width(10) + vbox1.pack_start(vbox2, True, True, 0) + vbox2.show() label = Gtk.Label(label=_("Packages mirrors are syncing with new " "packages")) - box2.pack_start(label, False, False, 0) - box2 = Gtk.HBox(homogeneous=False, spacing=10) - box2.set_border_width(5) - box1.pack_start(box2, False, True, 0) - box2.show() + vbox2.pack_start(label, False, False, 0) + hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox2.set_border_width(5) + vbox1.pack_start(hbox2, False, True, 0) + hbox2.show() ok_button = Gtk.Button(label=_("Close")) ok_button.connect("clicked", on_close, window) - box2.pack_end(ok_button, False, False, 0) + hbox2.pack_end(ok_button, False, False, 0) window.show_all() @@ -232,23 +232,23 @@ def __init__(self): window.set_border_width(8) window.connect("destroy", on_close, window) window.set_title(_("Server Unreachable")) - box1 = Gtk.VBox(homogeneous=False, spacing=0) - window.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + window.add(vbox1) + vbox1.show() + hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox2.set_border_width(10) + vbox1.pack_start(hbox2, True, True, 0) + hbox2.show() label = Gtk.Label(label=_("The server is unreachable. Your internet " "could\nbe down or software package server is down.")) - box2.pack_start(label, False, False, 0) - box2 = Gtk.HBox(homogeneous=False, spacing=10) - box2.set_border_width(5) - box1.pack_start(box2, False, True, 0) - box2.show() + hbox2.pack_start(label, False, False, 0) + hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox2.set_border_width(5) + vbox1.pack_start(hbox2, False, True, 0) + hbox2.show() ok_button = Gtk.Button(label=_("Close")) ok_button.connect("clicked", on_close, window) - box2.pack_end(ok_button, False, False, 0) + hbox2.pack_end(ok_button, False, False, 0) window.show_all() @@ -266,25 +266,25 @@ def __init__(self): window.set_border_width(8) window.connect("destroy", Gtk.main_quit) window.set_title(_("Something Is Wrong")) - box1 = Gtk.VBox(homogeneous=False, spacing=0) - window.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + window.add(vbox1) + vbox1.show() + hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox2.set_border_width(10) + vbox1.pack_start(hbox2, True, True, 0) + hbox2.show() label = Gtk.Label(label=_( "If you see this message it means that " "something is wrong.\n Please look at pkg upgrade " "output.")) - box2.pack_start(label, False, False, 0) - box2 = Gtk.HBox(homogeneous=False, spacing=10) - box2.set_border_width(5) - box1.pack_start(box2, False, True, 0) - box2.show() + hbox2.pack_start(label, False, False, 0) + hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=10) + hbox2.set_border_width(5) + vbox1.pack_start(hbox2, False, True, 0) + hbox2.show() ok_button = Gtk.Button(label=_("Close")) ok_button.connect("clicked", Gtk.main_quit) - box2.pack_end(ok_button, False, False, 0) + hbox2.pack_end(ok_button, False, False, 0) window.show_all() @@ -301,14 +301,14 @@ def __init__(self): window.set_title(_("Software Station")) window.connect("destroy", on_close, window) window.set_size_request(300, 80) - box1 = Gtk.VBox(homogeneous=False, spacing=0) - window.add(box1) - box1.show() + v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + window.add(v_box) + v_box.show() label = Gtk.Label(label=_('You need to be root')) - box1.pack_start(label, True, True, 0) - h_box = Gtk.HBox(homogeneous=False, spacing=0) + v_box.pack_start(label, True, True, 0) + h_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=0) h_box.show() - box1.pack_end(h_box, False, False, 5) + v_box.pack_end(h_box, False, False, 5) ok_button = Gtk.Button() ok_button.set_label(_("Close")) ok_button.connect("clicked", on_close, window) diff --git a/update_station/frontend.py b/update_station/frontend.py index c3538d1..a3d8d25 100644 --- a/update_station/frontend.py +++ b/update_station/frontend.py @@ -23,7 +23,6 @@ ) from update_station.backend import ( check_for_update, - get_packages_to_reinstall, get_pkg_upgrade_data, unlock_update_station, updating, @@ -123,13 +122,13 @@ def __init__(self): self.window.set_border_width(0) self.window.set_position(Gtk.WindowPosition.CENTER) self.window.set_default_icon_name('system-software-update') - box1 = Gtk.VBox(homogeneous=False, spacing=0) - self.window.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=0) - box2.set_border_width(20) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + self.window.add(vbox1) + vbox1.show() + vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + vbox2.set_border_width(20) + vbox1.pack_start(vbox2, True, True, 0) + vbox2.show() # Title title_text = _("Updates available!") @@ -137,7 +136,7 @@ def __init__(self): label=f"{title_text}" ) update_title_label.set_use_markup(True) - box2.pack_start(update_title_label, False, False, 0) + vbox2.pack_start(update_title_label, False, False, 0) self.tree_store = Gtk.TreeStore(str, bool) sw = Gtk.ScrolledWindow() sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN) @@ -149,13 +148,13 @@ def __init__(self): self.view.set_headers_visible(False) sw.add(self.view) sw.show() - box2.pack_start(sw, True, True, 10) - box2 = Gtk.HBox(homogeneous=False, spacing=10) - box2.set_border_width(5) - box1.pack_start(box2, False, False, 5) - box2.show() + vbox2.pack_start(sw, True, True, 10) + hbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=10) + hbox2.set_border_width(5) + vbox1.pack_start(hbox2, False, False, 5) + hbox2.show() # Add button - box2.pack_start(self.create_bbox(), True, True, 10) + hbox2.pack_start(self.create_bbox(), True, True, 10) self.window.show_all() def store(self): @@ -168,35 +167,36 @@ def store(self): u_num = 0 i_num = 0 ri_num = 0 - if bool(Data.packages_dictionary['remove']): - r_num = len(Data.packages_dictionary['remove']) - message = _('Installed packages to be REMOVED:') - message += f' {r_num}' - r_pinter = self.tree_store.append(None, (message, True)) - for line in Data.packages_dictionary['remove']: - self.tree_store.append(r_pinter, (line, True)) - if bool(Data.packages_dictionary['upgrade']): - u_num = len(Data.packages_dictionary['upgrade']) - message = _('Installed packages to be UPGRADED') - message += f' {u_num}' + if Data.packages_dictionary['upgrade']: + message = _('Installed packages to be upgraded:') + message += f' {Data.packages_dictionary["number_to_upgrade"]}' u_pinter = self.tree_store.append(None, (message, True)) for line in Data.packages_dictionary['upgrade']: self.tree_store.append(u_pinter, (line, True)) + if Data.packages_dictionary['downgrade']: + message = _('Installed packages to be downgraded:') + message += f' {Data.packages_dictionary["number_to_downgrade"]}' + d_pinter = self.tree_store.append(None, (message, True)) + for line in Data.packages_dictionary['downgrade']: + self.tree_store.append(d_pinter, (line, True)) if bool(Data.packages_dictionary['install']): - i_num = len(Data.packages_dictionary['install']) - message = _('New packages to be INSTALLED:') - message += f' {i_num}' + message = _('New packages to be installed:') + message += f' {Data.packages_dictionary["number_to_install"]}' i_pinter = self.tree_store.append(None, (message, True)) for line in Data.packages_dictionary['install']: self.tree_store.append(i_pinter, (line, True)) if bool(Data.packages_dictionary['reinstall']): - ri_num = len(Data.packages_dictionary['reinstall']) - message = _('Installed packages to be REINSTALLED:') - message += f' {ri_num}' + message = _('Installed packages to be reinstalled:') + message += f' {Data.packages_dictionary["number_to_reinstall"]}' ri_pinter = self.tree_store.append(None, (message, True)) for line in Data.packages_dictionary['reinstall']: self.tree_store.append(ri_pinter, (line, True)) - Data.total_packages = r_num + u_num + i_num + ri_num + if bool(Data.packages_dictionary['remove']): + message = _('Installed packages to be removed:') + message += f' {Data.packages_dictionary["number_to_remove"]}' + r_pinter = self.tree_store.append(None, (message, True)) + for line in Data.packages_dictionary['remove']: + self.tree_store.append(r_pinter, (line, True)) return self.tree_store def display(self, model: Gtk.TreeStore) -> Gtk.TreeView: @@ -235,22 +235,23 @@ def __init__(self): self.win.set_border_width(0) self.win.set_position(Gtk.WindowPosition.CENTER) self.win.set_default_icon_name('system-software-update') - box1 = Gtk.VBox(homogeneous=False, spacing=0) - self.win.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + self.win.add(vbox1) + vbox1.show() + vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=10) + vbox2.set_border_width(10) + vbox1.pack_start(vbox2, True, True, 0) + vbox2.show() self.pbar = Gtk.ProgressBar() self.pbar.set_show_text(True) self.pbar.set_fraction(0.0) # self.pbar.set_size_request(-1, 20) - box2.pack_start(self.pbar, False, False, 0) + vbox2.pack_start(self.pbar, False, False, 0) self.win.show_all() self.thr = threading.Thread(target=self.read_output, args=[self.pbar], daemon=True) self.thr.start() + def read_output(self, progress): """ Function that reads the output of the update to update the progress bar. @@ -258,10 +259,11 @@ def read_output(self, progress): """ fail = False update_pkg = False + option = '' packages = '' env = f'env ABI={Data.new_abi} ' if Data.major_upgrade else '' need_reboot_packages = set(json.loads(open(f'{lib_path}/need_reboot.json').read())) - upgrade_packages = set(re.findall(r"(\S+):", " ".join(Data.packages_dictionary['upgrade']))) + upgrade_packages = set(re.split(": | ", " ".join(Data.packages_dictionary['upgrade']))) reboot = bool(need_reboot_packages.intersection(upgrade_packages)) if len(Data.packages_dictionary['upgrade']) == 1 and 'pkg:' in Data.packages_dictionary['upgrade'][0]: update_pkg = True @@ -269,10 +271,10 @@ def read_output(self, progress): Data.second_update = True else: Data.second_update = False - howmany: float = (Data.total_packages * 5) + 45 - fraction: float = 1.0 / howmany - - # TODO: make a function for this part. + if Data.kernel_upgrade: + option = 'f' + howmany = (Data.packages_dictionary['total_of_packages'] * 7) + 45 + fraction = 1.0 / howmany if Data.backup: today = datetime.datetime.now().strftime("%Y-%m-%d") txt = _("Cleaning old boot environment") @@ -286,9 +288,8 @@ def read_output(self, progress): GLib.idle_add(update_progress, progress, fraction, txt) bectl.create_be(new_be_name=backup_name) sleep(1) - if Data.major_upgrade: - txt = _("Setting env and bootstrap pkg to upgrade") + txt = _("Fetching package updates") GLib.idle_add(update_progress, progress, fraction, txt) fetch = Popen( f'{env}env IGNORE_OSVERSION=yes ASSUME_ALWAYS_YES=yes pkg bootstrap -f', @@ -304,8 +305,7 @@ def read_output(self, progress): if fetch.poll() is not None: break fetch_text += stdout_line - GLib.idle_add(update_progress, progress, fraction, - stdout_line.strip()) + GLib.idle_add(update_progress, progress, fraction, stdout_line.strip()) if fetch.returncode != 0: stderr_line = fetch.stderr.read() fetch_text += stderr_line @@ -316,11 +316,11 @@ def read_output(self, progress): GLib.idle_add(self.win.destroy) GLib.idle_add(self.stop_tread, fail, update_pkg, reboot) return - txt = _("Downloading packages to upgrade") + txt = _("Fetching package updates") GLib.idle_add(update_progress, progress, fraction, txt) sleep(1) fetch = Popen( - f'{env}pkg-static upgrade -Fy{packages}', + f'{env}pkg-static upgrade -Fy{option}{packages}', shell=True, stdout=PIPE, stderr=PIPE, @@ -333,8 +333,7 @@ def read_output(self, progress): if fetch.poll() is not None: break fetch_text += stdout_line - GLib.idle_add(update_progress, progress, fraction, - stdout_line.strip()) + GLib.idle_add(update_progress, progress, fraction, stdout_line.strip()) if fetch.returncode != 0: stderr_line = fetch.stderr.read() fetch_text += stderr_line @@ -343,15 +342,15 @@ def read_output(self, progress): update_fail.close() fail = True else: - txt = _("Packages to upgrade downloaded") + txt = _("Package updates downloaded") GLib.idle_add(update_progress, progress, fraction, txt) sleep(1) - txt = _("Upgrading packages") + txt = _("Installing package updates") GLib.idle_add(update_progress, progress, fraction, txt) sleep(1) while True: install = Popen( - f'{env}pkg-static upgrade -y{packages}', + f'{env}pkg-static upgrade -y{option}{packages}', shell=True, stdout=PIPE, stderr=PIPE, @@ -364,8 +363,7 @@ def read_output(self, progress): if install.poll() is not None: break install_text += stdout_line - GLib.idle_add(update_progress, progress, fraction, - stdout_line.strip()) + GLib.idle_add(update_progress, progress, fraction, stdout_line.strip()) if install.returncode == 3: stderr_line = install.stderr.readline() if 'Fail to create temporary file' in stderr_line: @@ -418,75 +416,10 @@ def read_output(self, progress): fail = True break else: - txt = _("Packages upgraded") + txt = _("Software packages upgrade completed") GLib.idle_add(update_progress, progress, fraction, txt) sleep(1) break - if Data.kernel_upgrade: - all_packages = set(re.findall(r"(\S+):", " ".join(Data.packages_dictionary['reinstall']))) - all_packages.update(upgrade_packages) - packages_to_reinstall = set(get_packages_to_reinstall()) - packages = " ".join(list(packages_to_reinstall.difference(all_packages))) - txt = _("Downloading packages depending on kernel") - GLib.idle_add(update_progress, progress, fraction, txt) - sleep(1) - fetch = Popen( - f'{env}pkg-static upgrade -Fy {packages}', - shell=True, - stdout=PIPE, - stderr=PIPE, - close_fds=True, - universal_newlines=True - ) - fetch_text = "" - while True: - stdout_line = fetch.stdout.readline() - if fetch.poll() is not None: - break - fetch_text += stdout_line - GLib.idle_add(update_progress, progress, fraction, - stdout_line.strip()) - if fetch.returncode != 0: - stderr_line = fetch.stderr.read() - fetch_text += stderr_line - update_fail = open(f'{Data.home}/update.failed', 'w') - update_fail.writelines(fetch_text) - update_fail.close() - fail = True - else: - txt = _("Packages depending on kernel downloaded") - GLib.idle_add(update_progress, progress, fraction, txt) - sleep(1) - txt = _("Reinstalling packages depending on kernel") - GLib.idle_add(update_progress, progress, fraction, txt) - sleep(1) - install = Popen( - f'{env}pkg-static upgrade -fy {packages}', - shell=True, - stdout=PIPE, - stderr=PIPE, - close_fds=True, - universal_newlines=True - ) - install_text = "" - while True: - stdout_line = install.stdout.readline() - if install.poll() is not None: - break - install_text += stdout_line - GLib.idle_add(update_progress, progress, fraction, - stdout_line.strip()) - if install.returncode != 0: - stderr_line = install.stderr.readline() - install_text += stderr_line - update_fail = open(f'{Data.home}/update.failed', 'w') - update_fail.writelines(install_text) - update_fail.close() - fail = True - else: - txt = _("Packages depending on kernel reinstalled") - GLib.idle_add(update_progress, progress, fraction, txt) - sleep(1) GLib.idle_add(self.win.destroy) GLib.idle_add(self.stop_tread, fail, update_pkg, reboot) @@ -542,17 +475,17 @@ def __init__(self): self.win.set_border_width(0) self.win.set_position(Gtk.WindowPosition.CENTER) self.win.set_default_icon_name('system-software-update') - box1 = Gtk.VBox(homogeneous=False, spacing=0) - self.win.add(box1) - box1.show() - box2 = Gtk.VBox(homogeneous=False, spacing=10) - box2.set_border_width(10) - box1.pack_start(box2, True, True, 0) - box2.show() + vbox1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) + self.win.add(vbox1) + vbox1.show() + vbox2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=10) + vbox2.set_border_width(10) + vbox1.pack_start(vbox2, True, True, 0) + vbox2.show() self.pbar = Gtk.ProgressBar() self.pbar.set_show_text(True) self.pbar.set_fraction(0.0) - box2.pack_start(self.pbar, False, False, 0) + vbox2.pack_start(self.pbar, False, False, 0) self.win.show_all() self.thr = threading.Thread( target=self.check_for_update, From 09bdb44765d6ef9a93b5a4f4f265d6596de8b9c6 Mon Sep 17 00:00:00 2001 From: ericbsd Date: Tue, 25 Feb 2025 22:25:00 -0400 Subject: [PATCH 2/3] Fixed UpdateCompleted homogeneous variable --- update_station/dialog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/update_station/dialog.py b/update_station/dialog.py index eb80d79..00f4853 100644 --- a/update_station/dialog.py +++ b/update_station/dialog.py @@ -101,13 +101,13 @@ def __init__(self): window.connect("destroy", on_close, window) window.set_title(_("Update Completed")) window.set_default_icon_name('system-software-update') - v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, hhomogeneous=False, spacing=0) + v_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=False, spacing=0) window.add(v_box) v_box.show() label = Gtk.Label(label=_("""All software on this system is up to date.""")) v_box.set_border_width(5) v_box.pack_start(label, False, False, 5) - h_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, hhomogeneous=False, spacing=0) + h_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, homogeneous=False, spacing=0) # h_box.set_border_width(5) v_box.pack_start(h_box, False, True, 5) h_box.show() From d285e67ea690638b852a35774ff3ce497e2eb83d Mon Sep 17 00:00:00 2001 From: ericbsd Date: Wed, 26 Feb 2025 08:03:51 -0400 Subject: [PATCH 3/3] Changed sleeps --- update-station | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/update-station b/update-station index c7c33a1..146d197 100755 --- a/update-station +++ b/update-station @@ -66,16 +66,15 @@ def check(): Function that checks for updates. """ while True: - sleep(20) + sleep(60) if not repository_is_syncing(): if not Data.stop_pkg_refreshing: if not updating(): GLib.idle_add(update_tray) else: - print('True') GLib.idle_add(Data.system_tray.tray_icon().set_visible, False) # Wait for an hour to look for update - sleep(600) + sleep(3600) def check_now():