asyncjob: Simplify interface for simple_async

This commit is contained in:
Cole Robinson 2011-04-14 15:28:22 -04:00
parent 6ebf751299
commit 682c1d233b
2 changed files with 24 additions and 12 deletions

View File

@ -53,8 +53,20 @@ def cb_wrapper(callback, asyncjob, *args, **kwargs):
asyncjob.set_error(str(e), "".join(traceback.format_exc()))
def _simple_async(callback, args, title, text, parent, errorintro,
show_progress):
asyncjob = vmmAsyncJob(callback, args, title, text, parent.topwin,
show_progress, simplecb):
"""
@show_progress: Whether to actually show a progress dialog
@simplecb: If true, build a callback wrapper that ignores the asyncjob
param that's passed to every cb by default
"""
docb = callback
if simplecb:
def tmpcb(job, *args, **kwargs):
ignore = job
callback(*args, **kwargs)
docb = tmpcb
asyncjob = vmmAsyncJob(docb, args, title, text, parent.topwin,
show_progress=show_progress)
error, details = asyncjob.run()
if error is None:
@ -68,12 +80,15 @@ def _simple_async(callback, args, title, text, parent, errorintro,
class vmmAsyncJob(vmmGObjectUI):
@staticmethod
def simple_async(callback, args, title, text, parent, errorintro):
_simple_async(callback, args, title, text, parent, errorintro, True)
def simple_async(callback, args, title, text, parent, errorintro,
simplecb=True):
_simple_async(callback, args, title, text, parent, errorintro, True,
simplecb)
@staticmethod
def simple_async_noshow(callback, args, parent, errorintro):
_simple_async(callback, args, "", "", parent, errorintro, False)
def simple_async_noshow(callback, args, parent, errorintro, simplecb=True):
_simple_async(callback, args, "", "", parent, errorintro, False,
simplecb)
def __init__(self, callback, args, title, text, parent,

View File

@ -1026,23 +1026,20 @@ class vmmEngine(vmmGObject):
logging.debug("Starting vm '%s'." % vm.get_name())
def asyncfunc(asyncjob):
ignore = asyncjob
vm.startup()
if vm.hasSavedImage():
# VM will be restored, which can take some time, so show a
# progress dialog.
errorintro = _("Error restoring domain")
title = _("Restoring Virtual Machine")
text = _("Restoring virtual machine memory from disk")
vmmAsyncJob.simple_async(asyncfunc, [], title, text, src,
vmmAsyncJob.simple_async(vm.startup,
[], title, text, src,
errorintro)
else:
# Regular startup
errorintro = _("Error starting domain")
vmmAsyncJob.simple_async_noshow(asyncfunc, [], src, errorintro)
vmmAsyncJob.simple_async_noshow(vm.startup, [], src, errorintro)
def _do_shutdown_domain(self, src, uri, uuid):
conn = self._lookup_connection(uri)