From 84e6d584936077e2ec1d91fb644a3a76ed9219c6 Mon Sep 17 00:00:00 2001 From: Fuxino Date: Sun, 30 Apr 2023 11:53:31 +0200 Subject: [PATCH] Handle dbus exceptions --- simple_backup.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/simple_backup.py b/simple_backup.py index e06f6e7..6bfb256 100755 --- a/simple_backup.py +++ b/simple_backup.py @@ -299,15 +299,22 @@ def simple_backup(): backup = Backup(inputs, output, exclude, keep, backup_options) if backup.check_params(): - obj = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") - obj = dbus.Interface(obj, "org.freedesktop.Notifications") - obj.Notify("simple_backup", 0, "", "Starting backup...", "", [], {"urgency": 1}, 10000) + try: + obj = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") + obj = dbus.Interface(obj, "org.freedesktop.Notifications") + obj.Notify("simple_backup", 0, "", "Starting backup...", "", [], {"urgency": 1}, 10000) + except dbus.exceptions.DBusException: + pass + status = backup.run() - if status == 0: - obj.Notify("simple_backup", 0, "", "Backup finished.", "", [], {"urgency": 1}, 10000) - else: - obj.Notify("simple_backup", 0, "", "Backup finished. Some errors occurred.", "", [], {"urgency": 1}, 10000) + try: + if status == 0: + obj.Notify("simple_backup", 0, "", "Backup finished.", "", [], {"urgency": 1}, 10000) + else: + obj.Notify("simple_backup", 0, "", "Backup finished. Some errors occurred.", "", [], {"urgency": 1}, 10000) + except NameError: + pass if __name__ == '__main__':