Skip to content

Commit

Permalink
fix: reformat to please the formatting gods
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Jul 15, 2023
1 parent 0e1fa6e commit 38a18ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
24 changes: 14 additions & 10 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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 = [
Expand All @@ -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():
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 7 additions & 13 deletions src/ublue_update/update_checks/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,28 @@
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://"
url = current_image[1]
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"""
Expand Down

0 comments on commit 38a18ec

Please sign in to comment.