From 177c40d18fbff4830ee6a6a61e473a208a4cc3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 15 Dec 2013 22:51:42 +0100 Subject: [PATCH] qvm-tools: do not crash qvm-run/qvm-start --tray when no notification service available --- qvm-tools/qvm-run | 11 ++++++++--- qvm-tools/qvm-start | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/qvm-tools/qvm-run b/qvm-tools/qvm-run index deb1f0a2..99d64ae8 100755 --- a/qvm-tools/qvm-run +++ b/qvm-tools/qvm-run @@ -41,10 +41,12 @@ notify_object = None from qubes.qubes import defaults def tray_notify(str, label, timeout = 3000): - notify_object.Notify("Qubes", 0, label.icon, "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") + if notify_object: + notify_object.Notify("Qubes", 0, label.icon, "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") def tray_notify_error(str, timeout = 3000): - notify_object.Notify("Qubes", 0, "dialog-error", "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") + if notify_object: + notify_object.Notify("Qubes", 0, "dialog-error", "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") def vm_run_cmd(vm, cmd, options): if options.shutdown: @@ -169,7 +171,10 @@ def main(): if options.tray: global notify_object - notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") + try: + notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") + except dbus.DBusException as ex: + print >>sys.stderr, "WARNING: failed connect to tray notification service: %s" % str(ex) qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_reading() diff --git a/qvm-tools/qvm-start b/qvm-tools/qvm-start index 0ecd063d..d89642b9 100755 --- a/qvm-tools/qvm-start +++ b/qvm-tools/qvm-start @@ -31,10 +31,12 @@ import dbus notify_object = None def tray_notify(str, label, timeout = 3000): - notify_object.Notify("Qubes", 0, label.icon, "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") + if notify_object: + notify_object.Notify("Qubes", 0, label.icon, "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") def tray_notify_error(str, timeout = 3000): - notify_object.Notify("Qubes", 0, "dialog-error", "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") + if notify_object: + notify_object.Notify("Qubes", 0, "dialog-error", "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications") def tray_notify_generic(level, str): if level == "info": @@ -72,7 +74,10 @@ def main(): if options.tray: global notify_object - notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") + try: + notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications") + except dbus.DBusException as ex: + print >>sys.stderr, "WARNING: failed connect to tray notification service: %s" % str(ex) qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_reading()