[pykickstart] Reset method seen attrs when switching method (#1004889)

Vratislav Podzimek vpodzime at redhat.com
Tue Sep 10 08:25:33 UTC 2013


On Mon, 2013-09-09 at 15:21 -0700, Brian C. Lane wrote:
> From: "Brian C. Lane" <bcl at redhat.com>
> 
> The method initially gets set to cdrom, it can then be switched to
> another method via UI or when falling back to closest mirror if a repo
> isn't found. This would result in .seen to be set on multiple methods,
> and since .cdrom.seen was checked first it would be used for the
> attributes -- some of which don't exist.
> 
> This clears the .seen attr when switching methods or setting it to None.
> 
> It also fixes a problem where None was being returned for too many attrs
> which caused problems with the internal operations of copy.copy used by
> the software spoke to detect changes from the previous method settings.
> Only return None if the name is "method" otherwise pass it through to
> the superclass' __getattr__
> ---
>  pykickstart/commands/method.py | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/pykickstart/commands/method.py b/pykickstart/commands/method.py
> index 1e0cf90..0dbcb52 100644
> --- a/pykickstart/commands/method.py
> +++ b/pykickstart/commands/method.py
> @@ -28,6 +28,13 @@ class FC3_Method(KickstartCommand):
>      internals = ["method",
>                   "writePriority", "currentCmd", "currentLine", "handler", "lineno", "seen"]
>  
> +    _methods = ["cdrom", "harddrive", "nfs", "url"]
> +
> +    def _clear_seen(self):
> +        """ Reset all the method's seen attrs to False"""
> +        for method in self._methods:
> +            setattr(getattr(self.handler, method), "seen", False)
> +
>      def __getattr__(self, name):
>          if self.handler.cdrom.seen:
>              if name == "method":
> @@ -49,11 +56,15 @@ class FC3_Method(KickstartCommand):
>                  return "url"
>              else:
>                  return getattr(self.handler.url, name)
> -        else:
> +        elif name == "method":
>              return None
> +        else:
> +            return KickstartCommand.__getattr__(self, name)
>  
>      def __setattr__(self, name, value):
>          if name in self.internals:
> +            if name == "method":
> +                self._clear_seen()
>              if name == "method" and value == "cdrom":
>                  setattr(self.handler.cdrom, "seen", True)
>              elif name == "method" and value == "harddrive":
> @@ -88,6 +99,8 @@ class F19_Method(FC3_Method):
>      removedKeywords = FC3_Method.removedKeywords
>      removedAttrs = FC3_Method.removedAttrs
>  
> +    _methods = FC3_Method._methods + ["liveimg"]
> +
>      def __getattr__(self, name):
>          if self.handler.liveimg.seen:
>              if name == "method":
> @@ -99,6 +112,8 @@ class F19_Method(FC3_Method):
>  
>      def __setattr__(self, name, value):
>          if name in self.internals:
> +            if name == "method":
> +                self._clear_seen()
>              if name == "method" and value == "liveimg":
>                  setattr(self.handler.liveimg, "seen", True)
>              else:
ACK.

-- 
Vratislav Podzimek

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



More information about the anaconda-patches mailing list