Skip to content

Commit

Permalink
Merge pull request #2 from dashea/handle_header
Browse files Browse the repository at this point in the history
Add a %addon argument to reverse the display of the text
  • Loading branch information
vpodzime committed Feb 15, 2014
2 parents 41eb1d1 + 115c0cb commit 9a07523
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
5 changes: 5 additions & 0 deletions org_fedora_hello_world/gui/spokes/hello_world.py
Expand Up @@ -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:
Expand Down
43 changes: 42 additions & 1 deletion org_fedora_hello_world/ks/hello_world.py
Expand Up @@ -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__
Expand All @@ -49,6 +51,7 @@ def __init__(self, name):

AddonData.__init__(self, name)
self.text = ""
self.reverse = False

def __str__(self):
"""
Expand All @@ -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):
"""
Expand Down
5 changes: 5 additions & 0 deletions org_fedora_hello_world/tui/spokes/hello_world.py
Expand Up @@ -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:
Expand Down

0 comments on commit 9a07523

Please sign in to comment.