[blivet] Pack data for the wait_for_entropy callback
Vratislav Podzimek
vpodzime at redhat.com
Tue Nov 4 08:28:02 UTC 2014
Packing data into a namedtuple is good for keeping the API even if we need to
add some more parameters (fields) in the future. It also serves as a
documentation.
Also improve the documentation of the callbacks that are expected to be used.
Related: rhbz#1073679
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
blivet/callbacks.py | 11 +++++++++++
blivet/deviceaction.py | 3 ++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/blivet/callbacks.py b/blivet/callbacks.py
index b2e8c3a..742b768 100644
--- a/blivet/callbacks.py
+++ b/blivet/callbacks.py
@@ -48,6 +48,15 @@ def create_new_callbacks_register(create_format_pre=None,
object and to provide default values for non-specified fields (e.g. newly
added callbacks).
+ :type create_format_pre: :class:`.CreateFormatPreData` -> NoneType
+ :type create_format_post: :class:`.CreateFormatPostData` -> NoneType
+ :type resize_format_pre: :class:`.ResizeFormatPreData` -> NoneType
+ :type resize_format_post: :class:`.ResizeFormatPostData` -> NoneType
+ :param wait_for_entropy: callback for waiting for enough entropy whose return
+ value indicates whether continuing regardless of
+ available entropy should be forced (True) or not (False)
+ :type wait_for_entropy: :class:`.WaitForEntropyData` -> bool
+
"""
return _CallbacksRegister(create_format_pre, create_format_post,
@@ -62,3 +71,5 @@ ResizeFormatPreData = namedtuple("ResizeFormatPreData",
["msg"])
ResizeFormatPostData = namedtuple("ResizeFormatPostData",
["msg"])
+WaitForEntropyData = namedtuple("WaitForEntropyData",
+ ["msg", "min_entropy"])
diff --git a/blivet/deviceaction.py b/blivet/deviceaction.py
index 0aee993..b2229d3 100644
--- a/blivet/deviceaction.py
+++ b/blivet/deviceaction.py
@@ -33,6 +33,7 @@ from parted import partitionFlag, PARTITION_LBA
from .i18n import _, N_
from .callbacks import CreateFormatPreData, CreateFormatPostData
from .callbacks import ResizeFormatPreData, ResizeFormatPostData
+from .callbacks import WaitForEntropyData
import logging
log = logging.getLogger("blivet")
@@ -555,7 +556,7 @@ class ActionCreateFormat(DeviceAction):
if callbacks and callbacks.wait_for_entropy:
msg = _("Not enough entropy to create LUKS format. "
"%d bits are needed.") % min_required_entropy
- force_cont = callbacks.wait_for_entropy(msg, min_required_entropy)
+ force_cont = callbacks.wait_for_entropy(WaitForEntropyData(msg, min_required_entropy))
if force_cont:
# log warning and set format's required entropy to 0
--
1.9.3
More information about the anaconda-patches
mailing list