[PATCH] Allow AddonData classes to parse options in the %addon line
Vratislav Podzimek
vpodzime at redhat.com
Fri Feb 14 07:02:09 UTC 2014
On Thu, 2014-02-13 at 18:30 -0500, David Shea wrote:
> This adds a function AddonData.handle_header. The AddonSection parser
> will ignore any extra arguments to %addon when extracting the addon ID,
> and it will pass the remaining arguments to AddonData.handle_header.
> AddonData.handle_header will fail on extra arguments if not overridden
> in a subclass.
> ---
> pyanaconda/addons.py | 32 ++++++++++++++++++++++++++++----
> 1 file changed, 28 insertions(+), 4 deletions(-)
>
> diff --git a/pyanaconda/addons.py b/pyanaconda/addons.py
> index 8202a1d..3b658d5 100644
> --- a/pyanaconda/addons.py
> +++ b/pyanaconda/addons.py
> @@ -23,7 +23,8 @@ __all__ = ["AddonSection", "AddonRegistry", "AddonData", "collect_addon_paths"]
>
> import os
> from pykickstart.sections import Section
> -from pykickstart.options import KSOptionParser
> +from pykickstart.errors import KickstartParseError, formatErrorMsg
> +from pyanaconda.i18n import _
>
> def collect_addon_paths(toplevel_addon_paths, ui_subdir="gui"):
> """This method looks into the directories present
> @@ -129,6 +130,27 @@ class AddonData(object):
> """
> pass
>
> + def handle_header(self, lineno, args):
> + """Process additional arguments to the %addon line.
> +
> + This function receives any arguments on the %addon line after the
> + addon ID. For example, for the line:
> +
> + %addon com_example_foo --argument='example'
> +
> + This function would be called with args=["--argument='example'"].
> +
> + By default AddonData.handle_header will fail if passed any arguments,
> + so addon sections that take arguments must override this method.
> + """
> +
> + if args:
> + msg = _("Unhandled arguments on %%addon line for %s") % self.name
> + if lineno != None:
> + raise KickstartParseError(formatErrorMsg(lineno, msg=msg))
> + else:
> + raise KickstartParseError(msg)
> +
> def handle_line(self, line):
> """Process one kickstart line."""
> self.content += line
> @@ -160,14 +182,16 @@ class AddonSection(Section):
> def handleHeader(self, lineno, args):
> """Process the arguments to the %addon header."""
> Section.handleHeader(self, lineno, args)
> - op = KSOptionParser(version=self.version)
> - (_opts, extra) = op.parse_args(args=args[1:], lineno=lineno)
> - self.addon_id = extra[0]
> + self.addon_id = args[1]
>
> # if the addon is not registered, create dummy placeholder for it
> if self.addon_id and not hasattr(self.handler.addons, self.addon_id):
> setattr(self.handler.addons, self.addon_id, AddonData(self.addon_id))
>
> + # Parse additional arguments to %addon to the AddonData handler
> + addon = getattr(self.handler.addons, self.addon_id)
> + addon.handle_header(lineno, args[2:])
> +
> def finalize(self):
> """Let addon know no additional data will come."""
> Section.finalize(self)
This looks good to me. Patches for the AADG and HelloWorldAddon
welcome. :) And if you want this to be applied to the rhel7-branch,
don't forget to file a bug on Anaconda's insufficient addon API.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list