[PATCH 10/13] Implement and use a decorator for initialization needed

Vratislav Podzimek vpodzime at redhat.com
Thu Mar 13 19:57:08 UTC 2014


On Thu, 2014-03-13 at 11:26 -0700, Brian C. Lane wrote:
> 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.
I like having the code only in one place, but I agree one has to go
back and forth through the sources to find out what it does. Skipping
this one then.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list