Add a simple callback for all actions to report progress when running blivet.doIt() in blivet-gui
From: Vojtech Trefny vtrefny@redhat.com
Signed-off-by: Vojtech Trefny vtrefny@redhat.com --- blivet/callbacks.py | 11 ++++++++--- blivet/deviceaction.py | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/blivet/callbacks.py b/blivet/callbacks.py index 742b768..db52dc0 100644 --- a/blivet/callbacks.py +++ b/blivet/callbacks.py @@ -35,13 +35,15 @@ "create_format_post", "resize_format_pre", "resize_format_post", - "wait_for_entropy"]) + "wait_for_entropy", + "report_progress"])
def create_new_callbacks_register(create_format_pre=None, create_format_post=None, resize_format_pre=None, resize_format_post=None, - wait_for_entropy=None): + wait_for_entropy=None, + report_progress=None): """ A function for creating a new opaque object holding the references to callbacks. The point of this function is to hide the implementation of such @@ -56,12 +58,13 @@ def create_new_callbacks_register(create_format_pre=None, value indicates whether continuing regardless of available entropy should be forced (True) or not (False) :type wait_for_entropy: :class:`.WaitForEntropyData` -> bool + :type report_progress: :class:`.ReportProgressData` -> NoneType
"""
return _CallbacksRegister(create_format_pre, create_format_post, resize_format_pre, resize_format_post, - wait_for_entropy) + wait_for_entropy, report_progress)
CreateFormatPreData = namedtuple("CreateFormatPreData", ["msg"]) @@ -73,3 +76,5 @@ def create_new_callbacks_register(create_format_pre=None, ["msg"]) WaitForEntropyData = namedtuple("WaitForEntropyData", ["msg", "min_entropy"]) +ReportProgressData = namedtuple("ReportProgressData", + ["msg"]) diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py index 4d10765..d38f99c 100644 --- a/blivet/deviceaction.py +++ b/blivet/deviceaction.py @@ -32,7 +32,7 @@ from .i18n import _, N_ from .callbacks import CreateFormatPreData, CreateFormatPostData from .callbacks import ResizeFormatPreData, ResizeFormatPostData -from .callbacks import WaitForEntropyData +from .callbacks import WaitForEntropyData, ReportProgressData from .size import Size
import logging @@ -168,6 +168,10 @@ def execute(self, callbacks=None): if not self._applied: raise RuntimeError("cannot execute unapplied action")
+ if callbacks and callbacks.report_progress: + msg = _("Executing %(action)s") % {"action": str(self)} + callbacks.report_progress(ReportProgressData(msg)) + def cancel(self): """ cancel the action """ self._applied = False @@ -298,7 +302,7 @@ def __init__(self, device): DeviceAction.__init__(self, device)
def execute(self, callbacks=None): - super(ActionCreateDevice, self).execute(callbacks=None) + super(ActionCreateDevice, self).execute(callbacks=callbacks) self.device.create()
def requires(self, action): @@ -341,7 +345,7 @@ def __init__(self, device): DeviceAction.__init__(self, device)
def execute(self, callbacks=None): - super(ActionDestroyDevice, self).execute(callbacks=None) + super(ActionDestroyDevice, self).execute(callbacks=callbacks) self.device.destroy()
def requires(self, action): @@ -444,7 +448,7 @@ def apply(self): super(ActionResizeDevice, self).apply()
def execute(self, callbacks=None): - super(ActionResizeDevice, self).execute(callbacks=None) + super(ActionResizeDevice, self).execute(callbacks=callbacks) self.device.resize()
def cancel(self): @@ -525,7 +529,7 @@ def apply(self): super(ActionCreateFormat, self).apply()
def execute(self, callbacks=None): - super(ActionCreateFormat, self).execute(callbacks=None) + super(ActionCreateFormat, self).execute(callbacks=callbacks) if callbacks and callbacks.create_format_pre: msg = _("Creating %(type)s on %(device)s") % {"type": self.device.format.type, "device": self.device.path} callbacks.create_format_pre(CreateFormatPreData(msg)) @@ -647,7 +651,7 @@ def apply(self):
def execute(self, callbacks=None): """ wipe the filesystem signature from the device """ - super(ActionDestroyFormat, self).execute(callbacks=None) + super(ActionDestroyFormat, self).execute(callbacks=callbacks) status = self.device.status self.device.setup(orig=True) self.format.destroy() @@ -750,7 +754,7 @@ def apply(self): super(ActionResizeFormat, self).apply()
def execute(self, callbacks=None): - super(ActionResizeFormat, self).execute(callbacks=None) + super(ActionResizeFormat, self).execute(callbacks=callbacks) if callbacks and callbacks.resize_format_pre: msg = _("Resizing filesystem on %(device)s") % {"device": self.device.path} callbacks.resize_format_pre(ResizeFormatPreData(msg)) @@ -823,7 +827,7 @@ def cancel(self): super(ActionAddMember, self).cancel()
def execute(self, callbacks=None): - super(ActionAddMember, self).execute(callbacks=None) + super(ActionAddMember, self).execute(callbacks=callbacks) self.container.add(self.device)
def requires(self, action): @@ -887,7 +891,7 @@ def cancel(self): super(ActionRemoveMember, self).cancel()
def execute(self, callbacks=None): - super(ActionRemoveMember, self).execute(callbacks=None) + super(ActionRemoveMember, self).execute(callbacks=callbacks) self.container.remove(self.device)
def requires(self, action):
Looks good to me. I think this provides nice and generic interface for reporting and/or logging progress.
Added label: ACK.
Closed.
anaconda-patches@lists.fedorahosted.org