From 115c0cb92c57e0d6f1c44f0628a1ba11dcb95c7e Mon Sep 17 00:00:00 2001 From: David Shea Date: Sat, 15 Feb 2014 12:37:04 -0500 Subject: [PATCH] Add a %addon argument to reverse the display of the text This allows for a --reverse argument on the %addon line, such as: %addon org_fedora_hello_world --reverse text goes here %end If specified in the kickstart, the Hello World status displayed in the GUI and the TUI will be the reverse of what was input. This option is only exposed through kickstart. --- .../gui/spokes/hello_world.py | 5 +++ org_fedora_hello_world/ks/hello_world.py | 43 ++++++++++++++++++- .../tui/spokes/hello_world.py | 5 +++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/org_fedora_hello_world/gui/spokes/hello_world.py b/org_fedora_hello_world/gui/spokes/hello_world.py index 6f8e94f..65c2720 100644 --- a/org_fedora_hello_world/gui/spokes/hello_world.py +++ b/org_fedora_hello_world/gui/spokes/hello_world.py @@ -192,6 +192,11 @@ def status(self): """ text = self.data.addons.org_fedora_hello_world.text + + # If --reverse was specified in the kickstart, reverse the text + if self.data.addons.org_fedora_hello_world.reverse: + text = text[::-1] + if text: return _("Text set: %s") % text else: diff --git a/org_fedora_hello_world/ks/hello_world.py b/org_fedora_hello_world/ks/hello_world.py index f02ebf1..bc2e686 100644 --- a/org_fedora_hello_world/ks/hello_world.py +++ b/org_fedora_hello_world/ks/hello_world.py @@ -25,6 +25,8 @@ from pyanaconda.addons import AddonData from pyanaconda.constants import ROOT_PATH +from pykickstart.options import KSOptionParser + # export HelloWorldData class to prevent Anaconda's collect method from taking # AddonData class instead of the HelloWorldData class # :see: pyanaconda.kickstart.AnacondaKSHandler.__init__ @@ -49,6 +51,7 @@ def __init__(self, name): AddonData.__init__(self, name) self.text = "" + self.reverse = False def __str__(self): """ @@ -57,7 +60,45 @@ def __str__(self): """ - return "%%addon %s\n%s\n%%end" % (self.name, self.text) + addon_str = "%%addon %s" % self.name + + if self.reverse: + addon_str += "--reverse" + + addon_str += "\n%s\n%%end" % self.text + return addon_str + + def handle_header(self, lineno, args): + """ + The handle_header method is called to parse additional arguments in the + %addon section line. + + args is a list of all the arguments following the addon ID. For + example, for the line: + + %addon org_fedora_hello_world --reverse --arg2="example" + + handle_header will be called with args=['--reverse', '--arg2="example"'] + + :param lineno: the current line number in the kickstart file + :type lineno: int + :param args: the list of arguments from the %addon line + :type args: list + """ + + op = KSOptionParser() + op.add_option("--reverse", action="store_true", default=False, + dest="reverse", help="Reverse the display of the addon text") + (opts, extra) = op.parse_args(args=args, lineno=lineno) + + # Reject any additional arguments. Since AddonData.handle_header + # rejects any arguments, we can use it to create an error message + # and raise an exception. + if extra: + AddonData.handle_header(self, lineno, args) + + # Store the result of the option parsing + self.reverse = opts.reverse def handle_line(self, line): """ diff --git a/org_fedora_hello_world/tui/spokes/hello_world.py b/org_fedora_hello_world/tui/spokes/hello_world.py index dd6dbe7..666dc3f 100644 --- a/org_fedora_hello_world/tui/spokes/hello_world.py +++ b/org_fedora_hello_world/tui/spokes/hello_world.py @@ -163,6 +163,11 @@ def status(self): """ text = self.data.addons.org_fedora_hello_world.text + + # If --reverse was specified in the kickstart, reverse the text + if self.data.addons.org_fedora_hello_world.reverse: + text = text[::-1] + if text: return _("Text set: %s") % text else: