qvm-tools: do not crash qvm-run/qvm-start --tray when no notification service available

This commit is contained in:
Marek Marczykowski-Górecki 2013-12-15 22:51:42 +01:00
parent 2576e5000e
commit 177c40d18f
2 changed files with 16 additions and 6 deletions

View File

@ -41,10 +41,12 @@ notify_object = None
from qubes.qubes import defaults from qubes.qubes import defaults
def tray_notify(str, label, timeout = 3000): 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): 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): def vm_run_cmd(vm, cmd, options):
if options.shutdown: if options.shutdown:
@ -169,7 +171,10 @@ def main():
if options.tray: if options.tray:
global notify_object 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 = QubesVmCollection()
qvm_collection.lock_db_for_reading() qvm_collection.lock_db_for_reading()

View File

@ -31,10 +31,12 @@ import dbus
notify_object = None notify_object = None
def tray_notify(str, label, timeout = 3000): 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): 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): def tray_notify_generic(level, str):
if level == "info": if level == "info":
@ -72,7 +74,10 @@ def main():
if options.tray: if options.tray:
global notify_object 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 = QubesVmCollection()
qvm_collection.lock_db_for_reading() qvm_collection.lock_db_for_reading()