[PATCH 15/16] Add support for KS %addon section and the API+code to use it

Chris Lumens clumens at redhat.com
Thu Dec 13 20:50:02 UTC 2012


Something that just occurred to me when looking at this patch is that
ksvalidator is going to fail on processing any kickstart file with a
%addon section (or any other section defined outside pykickstart).  Do
we expect to see such kickstart files outside of anaconda?  If so, this
is going to need work.

> +    for path in toplevel_addon_paths:
> +        try:
> +            files = os.listdir(path)
> +        except OSError:
> +            files = []
> +                
> +        for addon_id in files:
> +            addon_ks_path = os.path.join(path, addon_id, "ks")
> +            if os.path.isdir(addon_ks_path):
> +                module_paths["ks"].append(("anaconda.addon.%s.ks.%%s" % addon_id, addon_ks_path))
> +
> +            addon_spoke_path = os.path.join(path, addon_id, ui_subdir, "spokes")
> +            if os.path.isdir(addon_spoke_path):
> +                module_paths["spokes"].append(("anaconda.addon.%s.spokes.%%s" % addon_id, addon_spoke_path))
> +
> +            addon_category_path = os.path.join(path, addon_id, ui_subdir, "categories")
> +            if os.path.isdir(addon_spoke_path):
> +                module_paths["categories"].append(("anaconda.addon.%s.categories.%%s" % addon_id, addon_category_path))

Do you mean pyanaconda.addon in all these paths?

> diff --git a/pyanaconda/install.py b/pyanaconda/install.py
> index 6754a0a..4e552ea 100644
> --- a/pyanaconda/install.py
> +++ b/pyanaconda/install.py
> @@ -52,7 +52,7 @@ def doConfiguration(storage, payload, ksdata, instClass):
>      from pyanaconda import progress
>      from pyanaconda.kickstart import runPostScripts
>  
> -    progress.send_init(4)
> +    progress.send_init(5)
>  
>      # Now run the execute methods of ksdata that require an installed system
>      # to be present first.
> @@ -79,6 +79,9 @@ def doConfiguration(storage, payload, ksdata, instClass):
>          ksdata.group.execute(storage, ksdata, instClass, u)
>          ksdata.user.execute(storage, ksdata, instClass, u)
>  
> +    with progress_report(_("Configuring addons")):
> +        ksdata.addon.execute(storage, ksdata, instClass, u)
> +
>      with progress_report(_("Running post install scripts")):
>          runPostScripts(ksdata.scripts)
>  

You may want to conditionalize these two so that they only happen if
there are addons to begin with.

> @@ -78,6 +80,7 @@ packagesSeen = False
>  # so it needs to know about them in some additional way: have the topology ready.
>  topology = None
>  
> +
>  class AnacondaKSScript(KSScript):
>      def run(self, chroot):
>          if self.inChroot:
> @@ -1342,11 +1345,38 @@ dataMap = {
>  
>  superclass = returnClassForVersion()
>  
> +    
>  class AnacondaKSHandler(superclass):
> -    def __init__ (self):
> +    AddonClassType = AddonData
> +    
> +    def __init__ (self, addon_paths = []):
>          superclass.__init__(self, commandUpdates=commandMap, dataUpdates=dataMap)
>          self.onPart = {}
>  
> +        # collect all kickstart addons for anaconda to addons dictionary
> +        # which maps addon_id to it's own data structure based on BaseData
> +        # with execute method
> +        addons = {}
> +
> +        # collect all AddonData subclasses from
> +        # for p in addon_paths: <p>/<plugin id>/ks/*.(py|so)
> +        # and register them under <plugin id> name
> +        for module_name, path in addon_paths:
> +            addon_id = os.path.basename(os.path.dirname(os.path.abspath(path)))
> +            if not os.path.isdir(path):
> +                continue
> +
> +            classes = collect(module_name, path, lambda cls: issubclass(cls, self.AddonClassType))
> +            print classes
> +            if classes:
> +                addons[addon_id] = classes[0](name = addon_id)
> +        
> +        # Prepare the final structures for 3rd party addons
> +        self.addon = AddonRegistry(addons)    
> +
> +    def __str__(self):
> +        return superclass.__str__(self) + "\n" +  str(self.addon)
> +        
>  class AnacondaPreParser(KickstartParser):
>      # A subclass of KickstartParser that only looks for %pre scripts and
>      # sets them up to be run.  All other scripts and commands are ignored.

This will all get executed twice, just so you know:  Once for processing
the kickstart file in the special %pre step, and once for the real pass.
That may not matter.  I don't know how much stuff is expected to happen
in this code and how many addons we realistically expect.  It might
also be best in its own method.

- Chris


More information about the anaconda-patches mailing list