#!/usr/bin/env python3 # SPDX-License-Identifier: CC0-1.0 # # Copyright (C) 2024 Wojtek Kosior import yaml import sys def read_APT_data(yaml_path): if yaml_path: with open(yaml_path) as inp: return yaml.safe_load(inp) else: return yaml.safe_load(sys.stdin) def group_has_sector(group, sector): group_sectors = group.get("sectors", []) if sector is None: return not group_sectors for sector_obj in group_sectors: if sector_obj["sector"] == sector: return True def group_has_goal(group, goal): group_goals = group.get("goals", []) if goal is None: return not group_goals for goal_obj in group_goals: if goal_obj["goal"] == goal: return True dashes = ''.join('-' for _ in range(24)) def print_tables(APT_data, out=sys.stdout): all_groups = APT_data["groups"] all_goals = sorted({goal["goal"] for group in all_groups for goal in group.get("goals", [])}) all_origins = sorted({group["origin"] for group in all_groups}) all_sectors = sorted({sector["sector"] for group in all_groups for sector in group.get("sectors", [])}) separator_line = f"|{'|'.join(dashes for _ in [None] + all_origins)}|" first = True for sector in all_sectors: if first: first = False else: print("\\newpage") groups = [group for group in all_groups if group_has_sector(group, sector)] def make_group_listing(origin, goal): return ", ".join(group["name"] for group in groups if (group["origin"] == origin and group_has_goal(group, goal))) print(f"### {sector}") print() print(f"|**goal \ origin**|**{'**|**'.join(all_origins)}**|") for goal in all_goals: group_listings = [make_group_listing(origin, goal) or ' ' for origin in all_origins] print(separator_line) print(f"|**{goal}**|{'|'.join(group_listings)}|") # Groups with no documented goal (if there are such ones) group_listings = [make_group_listing(origin, None) for origin in all_origins] if any(group_listings): print(separator_line) print(f"|*not documented*|{'|'.join(group_listings)}|") print() if __name__ == "__main__": print_tables(read_APT_data(None if len(sys.argv) < 2 else sys.argv[1]))