diff --git a/src/ublue_update/cli.py b/src/ublue_update/cli.py index 494fcae..06df990 100644 --- a/src/ublue_update/cli.py +++ b/src/ublue_update/cli.py @@ -9,19 +9,20 @@ from ublue_update.notification_manager import NotificationManager from ublue_update.update_checks.system import system_update_check + def ask_for_updates(): - """Only display override notification if checks failed""" - if dbus_notify and checks_failed: + if dbus_notify: update_notif = notification_manager.notification( "System Updater", "Update available, but system checks failed. Update now?", ) update_notif.add_action( - 'universal-blue-update-confirm', - 'Confirm', + "universal-blue-update-confirm", + "Confirm", lambda: run_updates(), ) - update_notif.show(15) + update_notif.show(15) + def check_for_updates(checks_failed: bool) -> bool: """Tracks whether any updates are available""" @@ -34,6 +35,7 @@ def check_for_updates(checks_failed: bool) -> bool: log.info("No updates are available.") return False + def check_cpu_load() -> dict: # get load average percentage in last 5 minutes: # https://psutil.readthedocs.io/en/latest/index.html?highlight=getloadavg @@ -70,7 +72,8 @@ def check_battery_status() -> dict: "message": f"Battery less than {min_battery_percent}%", } -def update_inhibitors_failed(update_checks_failed: bool): + +def update_inhibitors_failed(update_checks_failed: bool, failures: list): # log the failed update if check_for_updates(update_checks_failed): ask_for_updates() @@ -79,6 +82,7 @@ def update_inhibitors_failed(update_checks_failed: bool): exception_log = "\n - ".join(failures) raise Exception(f"update failed to pass checks: \n - {exception_log}") + def check_inhibitors() -> bool: update_inhibitors = [ @@ -87,13 +91,13 @@ def check_inhibitors() -> bool: check_cpu_load(), ] - failures : arr = [] + failures = [] update_checks_failed = False for inhibitor_result in update_inhibitors: if not inhibitor_result["passed"]: update_checks_failed = True failures.append(inhibitor_result["message"]) - return update_checks_failed + return update_checks_failed, failures def load_config(): @@ -193,9 +197,9 @@ def main(): update_checks_failed = False if not args.force and not args.updatecheck: - update_checks_failed = check_inhibitors() + update_checks_failed, failures = check_inhibitors() if update_checks_failed and not args.check: - update_inhibitors_failed() + update_inhibitors_failed(failures) if args.updatecheck: update_available = check_for_updates(False) diff --git a/src/ublue_update/update_checks/system.py b/src/ublue_update/update_checks/system.py index a4b9067..bce262f 100644 --- a/src/ublue_update/update_checks/system.py +++ b/src/ublue_update/update_checks/system.py @@ -10,26 +10,20 @@ def skopeo_inspect(latest_image: str): """Inspect latest image with Skopeo""" inspect = "skopeo inspect " + latest_image - out = run( - inspect, - shell=True, - stdout=PIPE).stdout + out = run(inspect, shell=True, stdout=PIPE).stdout """Parse and return digest""" - digest = loads(out)['Digest'] + digest = loads(out)["Digest"] return digest def system_update_check(): """Pull deployment status via rpm-ostree""" status = "rpm-ostree status --json" - out = run( - status, - shell=True, - stdout=PIPE).stdout + out = run(status, shell=True, stdout=PIPE).stdout """Parse installation digest and image""" - deployments = loads(out)['deployments'][0] - installation_digest = deployments['base-commit-meta']['ostree.manifest-digest'] - current_image = deployments['container-image-reference'].split(':') + deployments = loads(out)["deployments"][0] + installation_digest = deployments["base-commit-meta"]["ostree.manifest-digest"] + current_image = deployments["container-image-reference"].split(":") """Dissect current image to form URL to latest image""" protocol = "docker://" @@ -37,7 +31,7 @@ def system_update_check(): tag = current_image[2] """Pull digest from latest image""" - latest_image = protocol + url + ':' + tag + latest_image = protocol + url + ":" + tag latest_digest = skopeo_inspect(latest_image) """Compare current digest to latest digest"""