Skip to content

Commit

Permalink
extracted methods from the main function
Browse files Browse the repository at this point in the history
also removed unnecessary loops
  • Loading branch information
vojtapolasek committed Dec 13, 2022
1 parent 332a63e commit c198cc2
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions build-scripts/update_cpe_conditionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,32 @@ def main():
args.build_config_yaml, args.product_yaml)
product_cpes = ProductCPEs()
product_cpes.load_cpes_from_directory_tree(args.cpe_items_dir, env_yaml)
for remediation_type in args.remediation_types:
for cpe_item in product_cpes.get_all_cpes():
load_conditional_to_cpe_item(cpe_item, remediation_type, args.fixes_from_templates_dir)
product_cpes.add_cpe_item(cpe_item)
cpe_item_path = os.path.join(args.cpe_items_dir, cpe_item.id_+".yml")
cpe_item.dump_yaml(cpe_item_path)
for remediation_type in args.remediation_types:
for platform_file in os.listdir(args.platforms_dir):
platform_path = os.path.join(args.platforms_dir, platform_file)
try:
platform = ssg.build_yaml.Platform.from_yaml(platform_path, env_yaml, product_cpes)
except ssg.build_yaml.DocumentationNotComplete:
# Happens on non-debug build when a platform is
# "documentation-incomplete"
continue
update_cpe_items(
product_cpes, args.remediation_types, args.fixes_from_templates_dir, args.cpe_items_dir)
update_platforms(product_cpes, env_yaml, args.remediation_types, args.platforms_dir)


def update_cpe_items(product_cpes, remediation_types, fixes_from_templates_dir, cpe_items_dir):
for cpe_item in product_cpes.get_all_cpes():
for remediation_type in remediation_types:
load_conditional_to_cpe_item(cpe_item, remediation_type, fixes_from_templates_dir)
product_cpes.add_cpe_item(cpe_item)
cpe_item_path = os.path.join(cpe_items_dir, cpe_item.id_+".yml")
cpe_item.dump_yaml(cpe_item_path)


def update_platforms(product_cpes, env_yaml, remediation_types, platforms_dir):
for platform_file in os.listdir(platforms_dir):
platform_path = os.path.join(platforms_dir, platform_file)
try:
platform = ssg.build_yaml.Platform.from_yaml(platform_path, env_yaml, product_cpes)
except ssg.build_yaml.DocumentationNotComplete:
# Happens on non-debug build when a platform is
# "documentation-incomplete"
continue
for remediation_type in remediation_types:
platform.update_conditional_from_cpe_items(remediation_type, product_cpes)
platform.dump_yaml(platform_path)
platform.dump_yaml(platform_path)


def load_conditional_to_cpe_item(cpe, remediation_type, fixes_path):
Expand Down

0 comments on commit c198cc2

Please sign in to comment.