[PATCH 10/13] Implement and use a decorator for initialization needed
Brian C. Lane
bcl at redhat.com
Thu Mar 13 18:26:29 UTC 2014
On Mon, Mar 10, 2014 at 02:22:16PM +0100, Vratislav Podzimek wrote:
> Some functions/callbacks need the Custom spoke to be initialized to run. It's
> easier to have the code in one place and reuse it as a decorator.
>
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
> pyanaconda/ui/gui/spokes/custom.py | 37 +++++++++++++++++++++----------------
> 1 file changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
> index faaa1f7..24e8dab 100644
> --- a/pyanaconda/ui/gui/spokes/custom.py
> +++ b/pyanaconda/ui/gui/spokes/custom.py
> @@ -84,6 +84,8 @@ from pyanaconda.ui.gui.categories.system import SystemCategory
> from gi.repository import Gdk, Gtk
> from gi.repository.AnacondaWidgets import MountpointSelector
>
> +from functools import wraps
> +
> import logging
> log = logging.getLogger("anaconda")
>
> @@ -120,6 +122,18 @@ unrecoverable_error_msg = N_("Storage configuration reset due to unrecoverable "
> partition_only_format_types = ["efi", "macefi", "prepboot", "biosboot",
> "appleboot"]
>
> +def needs_init(func):
> + """Decorator for functions that require the spoke to be initialized to run"""
> +
> + @wraps(func)
> + def decorated(self, *args, **kwargs):
> + if not self._initialized:
> + return
> + else:
> + return func(self, *args, **kwargs)
> +
> + return decorated
The method's behavior is now hidden and non-obvious, adding one more
layer of things to remember/dig through when debugging. I don't like it.
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
More information about the anaconda-patches
mailing list