Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChoicesXMLGenerator recursive child items #149

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CommonProcessors/ChoicesXMLGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class ChoicesXMLGenerator(Processor):
"description": "Path to save the choices.xml file.",
"required": False,
},
"recursive_child_items": {
"description": "Enables recursively identifying child items of child items",
"default": "False",
"required": False,
}
}
output_variables = {}

Expand Down Expand Up @@ -83,13 +88,15 @@ def output_showchoicesxml(self, choices_pkg_path):
if error:
raise ProcessorError("No Plist generated from installer command")

def parse_choices_list(self, child_items, desired_choices):
def parse_choices_list(self, child_items, desired_choices, recursive_child_items = False):
"""Generates the python dictionary of choices.
Desired choices are given the choice attribute '1' (chosen).
Other choices found are given the choice attribute '0'
(not chosen)."""
parsed_choices = []
for child_dict in child_items:
if recursive_child_items and child_dict["childItems"]:
parsed_choices.extend(self.parse_choices_list(child_dict["childItems"], desired_choices, recursive_child_items))
try:
choice_identifier = child_dict["choiceIdentifier"]
if choice_identifier in desired_choices:
Expand Down Expand Up @@ -127,14 +134,17 @@ def main(self):
choices_pkg_path = self.env.get("choices_pkg_path")
desired_choices = self.env.get("desired_choices")
choices_xml_dest = self.env.get("choices_xml_dest")
recursive_child_items = False

if not choices_pkg_path:
self.output("No package selected!")
if not desired_choices:
self.output("No choices means an empty package!")
if str(self.env.get("recursive_child_items")).lower() == "true":
recursive_child_items = True

child_items = self.output_showchoicesxml(choices_pkg_path)
parsed_choices = self.parse_choices_list(child_items, desired_choices)
parsed_choices = self.parse_choices_list(child_items, desired_choices, recursive_child_items)
self.write_choices_xml(parsed_choices, choices_xml_dest)


Expand Down