Skip to content

Commit

Permalink
Remove notification manager (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh authored Aug 26, 2023
2 parents f99eb4a + 5817e31 commit c5b36d6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 112 deletions.
2 changes: 0 additions & 2 deletions Containerfile.builder
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ RUN dnf install \
FROM builder AS rpm

RUN make build-rpm


8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Small update program written in python intended for use in Universal Blue, execu

Includes systemd timers and services for auto update

dependencies (fedora): ```sudo dnf install python3-notify2 python3-psutil```
dependencies (fedora): ```sudo dnf install python3-psutil libnotify```


# Usage
Expand Down Expand Up @@ -45,11 +45,11 @@ options:
## Location
valid config paths (in order of priority)

```"$HOME"/.config/ublue-update/ublue-update.conf```
```"$HOME"/.config/ublue-update/ublue-update.toml```

```/etc/ublue-update/ublue-update.conf```
```/etc/ublue-update/ublue-update.toml```

```/usr/etc/ublue-update/ublue-update.conf```
```/usr/etc/ublue-update/ublue-update.toml```


## Config Variables
Expand Down
6 changes: 5 additions & 1 deletion files/usr/lib/systemd/user/ublue-update.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[Unit]
Description=auto-update oneshot service
Description=Universal Blue Update Oneshot Service

[Service]
Restart=on-failure
RestartSec=1h
Type=oneshot
ExecStart=/usr/bin/ublue-update


7 changes: 4 additions & 3 deletions files/usr/lib/systemd/user/ublue-update.timer
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[Unit]
Description=auto update system timer for uBlue
Description=Auto Update System Timer For Universal Blue
Wants=network-online.target

[Timer]
OnBootSec=15min
OnUnitInactiveSec=6h
RandomizedDelaySec=10m
OnBootSec=2m
OnCalendar=*-*-* 4:00:00
Persistent=true

[Install]
Expand Down
55 changes: 31 additions & 24 deletions src/ublue_update/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,36 @@
import tomllib
import argparse

from ublue_update.notification_manager import NotificationManager
from ublue_update.update_checks.system import system_update_check


def notify(title: str, body: str, actions: list = [], expire_time: int = 0):
args = [
"/usr/bin/notify-send",
title,
body,
"--app-name=Univeral Blue Updater",
"--icon=software-update-available-symbolic",
]
if expire_time != 0:
args.append(f"--expire-time={expire_time}")
if actions != []:
for action in actions:
args.append(f"--action={action}")
out = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return out


def ask_for_updates():
update_notif = notification_manager.notification(
out = notify(
"System Updater",
"Update available, but system checks failed. Update now?",
["universal-blue-update-confirm=Confirm"],
15000,
)
update_notif.add_action(
"universal-blue-update-confirm",
"Confirm",
lambda: run_updates(),
)
update_notif.show(15)
# if the user has confirmed
if "universal-blue-update-confirm" in out.stdout.decode("utf-8"):
run_updates()


def check_for_updates(checks_failed: bool) -> bool:
Expand Down Expand Up @@ -136,6 +151,8 @@ def load_value(key, value):
def run_updates():
root_dir = "/etc/ublue-update.d/"

log.info("Running system update")

for root, dirs, files in os.walk(root_dir):
for file in files:
full_path = root_dir + str(file)
Expand All @@ -150,17 +167,17 @@ def run_updates():
log.info(f"{full_path} returned error code: {out.returncode}")
log.info(f"Program output: \n {out.stdout}")
if dbus_notify:
notification_manager.notification(
notify(
"System Updater",
f"Error in update script: {file}, check logs for more info",
).show(5)
)
else:
log.info(f"could not execute file {full_path}")
if dbus_notify:
notification_manager.notification(
notify(
"System Updater",
"System update complete, reboot for changes to take effect",
).show(5)
)
log.info("System update complete")
os._exit(0)

Expand All @@ -178,15 +195,6 @@ def run_updates():
)
log = logging.getLogger(__name__)

notification_manager = None

# Sometimes the system doesn't have a running dbus session or a notification daemon
try:
notification_manager = NotificationManager("Universal Blue Updater")
except Exception:
dbus_notify = False


def main():

# setup argparse
Expand Down Expand Up @@ -229,9 +237,8 @@ def main():
# system checks passed
log.info("System passed all update checks")
if dbus_notify:
notification_manager.notification(
notify(
"System Updater",
"System passed checks, updating ...",
).show(5)

)
run_updates()
78 changes: 0 additions & 78 deletions src/ublue_update/notification_manager.py

This file was deleted.

1 change: 1 addition & 0 deletions ublue-update.spec.rpkg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BuildRequires: pyproject-rpm-macros
BuildRequires: python-setuptools_scm
BuildRequires: python-wheel
Requires: skopeo
Requires: libnotify

%global sub_name %{lua:t=string.gsub(rpm.expand("%{NAME}"), "^ublue%-", ""); print(t)}

Expand Down

0 comments on commit c5b36d6

Please sign in to comment.