diff --git a/dist/tools/features_yaml2mx/features_yaml2mx.py b/dist/tools/features_yaml2mx/features_yaml2mx.py index c15ec04e2c16..37a7698beca1 100755 --- a/dist/tools/features_yaml2mx/features_yaml2mx.py +++ b/dist/tools/features_yaml2mx/features_yaml2mx.py @@ -55,49 +55,40 @@ def write_makefile(outfile, yaml_path, parsed): outfile.flush() -def write_md_section(outfile, section, content, level): +def write_md_section(outfile, group, level): """ Write a section documenting certain features to the given file in markdown format. :param outfile: The file to write the section to :type outfile: file - :param section: Name of the section (a.k.a. section title) - :type section: str - :param content: The section content (e.g. a subtree from the parsed YAML) - :type content: dict + :param group: The group content (e.g. a subtree from the parsed YAML) + :type group: dict :param level: The current section level (e.g. 1=section, 2=subsection) :type level: int """ - outfile.write("#" * level + f" {section}\n") - if "help" in content: + title = group.get("title") + outfile.write("#" * level + f" {title}" if title else "" + "\n") + if "help" in group: outfile.write("\n") - outfile.write(content["help"]) + outfile.write(group["help"]) outfile.write("\n") - if "features" in content: + if "features" in group: outfile.write("\n") outfile.write("""\ | Feature | Description | |:--------------------------------- |:----------------------------------------------------------------------------- | """) - for feature, description in content["features"].items(): - if not isinstance(description, str): - sys.exit(f"expected description for feature \"{feature}\" " + - f"to be a string, but is {description}") - feature = f"`{feature}`" - description = description.strip().replace("\n", " ") - outfile.write(f"| {feature:<33} | {description:<77} |\n") + for feature in group["features"]: + name = f"`{feature['name']}`" + description = feature['help'].strip().replace("\n", " ") + outfile.write(f"| {name:<33} | {description:<77} |\n") - if not isinstance(content, dict): - sys.exit(f"Expected \"{content}\" to be a dict. " + - "(Wrong indent? Missing `features:` before feature dict?)") - - for subsection, subcontent in content.items(): - if subsection not in ("help", "features"): - outfile.write("\n") - write_md_section(outfile, subsection, subcontent, level + 1) + for group in group.get('groups', []): + outfile.write("\n") + write_md_section(outfile, group, level + 1) def write_mdfile(outfile, yaml_path, parsed): @@ -123,12 +114,7 @@ def write_mdfile(outfile, yaml_path, parsed): [TOC] """) - first_section = True - for section, content in parsed.items(): - if not first_section: - outfile.write("\n") - write_md_section(outfile, section, content, 1) - first_section = False + write_md_section(outfile, parsed, 0) def convert_features(yaml_file, mk_file, md_file):