dom0/qvm-tools: add GUI (tray balloon) error reporing to qvm-start and extend it in qvm-run (#534)

This commit is contained in:
Marek Marczykowski 2012-04-24 01:40:56 +02:00
parent 705699baf2
commit 7d799e1d12
2 changed files with 22 additions and 2 deletions

View File

@ -87,6 +87,8 @@ def vm_run_cmd(vm, cmd, options):
notify_function = tray_notify_generic if options.tray else None, notify_function = tray_notify_generic if options.tray else None,
passio = options.passio, localcmd = options.localcmd) passio = options.passio, localcmd = options.localcmd)
except QubesException as err: except QubesException as err:
if options.tray:
tray_notify_error(str(err))
print >> sys.stderr, "ERROR: %s" % str(err) print >> sys.stderr, "ERROR: %s" % str(err)
exit(1) exit(1)

View File

@ -26,13 +26,24 @@ from optparse import OptionParser
import subprocess import subprocess
import os import os
import sys import sys
import dbus
qubes_guid_path = "/usr/bin/qubes_guid" qubes_guid_path = "/usr/bin/qubes_guid"
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")
def tray_notify_error(str, timeout = 3000):
notify_object.Notify("Qubes", 0, "dialog-error", "Qubes", str, [], [], timeout, dbus_interface="org.freedesktop.Notifications")
def main(): def main():
usage = "usage: %prog [options] <vm-name>" usage = "usage: %prog [options] <vm-name>"
parser = OptionParser (usage) parser = OptionParser (usage)
parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True) parser.add_option ("-q", "--quiet", action="store_false", dest="verbose", default=True)
parser.add_option ("--tray", action="store_true", dest="tray", default=False,
help="Use tray notifications instead of stdout" )
parser.add_option ("--no-guid", action="store_true", dest="noguid", default=False, parser.add_option ("--no-guid", action="store_true", dest="noguid", default=False,
help="Do not start the GUId (ignored)") help="Do not start the GUId (ignored)")
parser.add_option ("--drive", dest="drive", default=None, parser.add_option ("--drive", dest="drive", default=None,
@ -53,6 +64,10 @@ def main():
parser.error ("You must specify VM name!") parser.error ("You must specify VM name!")
vmname = args[0] vmname = args[0]
if options.tray:
global notify_object
notify_object = dbus.SessionBus().get_object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
qvm_collection = QubesVmCollection() qvm_collection = QubesVmCollection()
qvm_collection.lock_db_for_reading() qvm_collection.lock_db_for_reading()
qvm_collection.load() qvm_collection.load()
@ -89,7 +104,10 @@ def main():
try: try:
vm.verify_files() vm.verify_files()
xid = vm.start(verbose=options.verbose, preparing_dvm=options.preparing_dvm, start_guid=not options.noguid) xid = vm.start(verbose=options.verbose, preparing_dvm=options.preparing_dvm, start_guid=not options.noguid)
except (IOError, OSError, QubesException) as err: except (IOError, OSError, QubesException, MemoryError) as err:
if options.tray:
tray_notify_error(str(err))
else:
print >> sys.stderr, "ERROR: {0}".format(err) print >> sys.stderr, "ERROR: {0}".format(err)
exit (1) exit (1)