From 682c1d233b81a115fbaea451819f4e2163523927 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 14 Apr 2011 15:28:22 -0400 Subject: [PATCH] asyncjob: Simplify interface for simple_async --- src/virtManager/asyncjob.py | 27 +++++++++++++++++++++------ src/virtManager/engine.py | 9 +++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/virtManager/asyncjob.py b/src/virtManager/asyncjob.py index 55bf4bf36..a6bc7e890 100644 --- a/src/virtManager/asyncjob.py +++ b/src/virtManager/asyncjob.py @@ -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, diff --git a/src/virtManager/engine.py b/src/virtManager/engine.py index e004f68d1..4ed408b7e 100644 --- a/src/virtManager/engine.py +++ b/src/virtManager/engine.py @@ -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)