tools/net/ynl/pyynl/ynl_gen_rst.py
Source file repositories/reference/linux-study-clean/tools/net/ynl/pyynl/ynl_gen_rst.py
File Facts
- System
- Linux kernel
- Corpus path
tools/net/ynl/pyynl/ynl_gen_rst.py- Extension
.py- Size
- 2581 bytes
- Lines
- 86
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: tools
- Status
- atlas-only
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0
# -*- coding: utf-8; mode: python -*-
"""
Script to auto generate the documentation for Netlink specifications.
:copyright: Copyright (C) 2023 Breno Leitao <leitao@debian.org>
:license: GPL Version 2, June 1991 see linux/COPYING for details.
This script performs extensive parsing to the Linux kernel's netlink YAML
spec files, in an effort to avoid needing to heavily mark up the original
YAML file. It uses the library code from scripts/lib.
"""
import os.path
import pathlib
import sys
import argparse
import logging
# pylint: disable=no-name-in-module,wrong-import-position
sys.path.append(pathlib.Path(__file__).resolve().parent.as_posix())
from lib import YnlDocGenerator # pylint: disable=C0413
def parse_arguments() -> argparse.Namespace:
"""Parse arguments from user"""
parser = argparse.ArgumentParser(description="Netlink RST generator")
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-o", "--output", help="Output file name")
# Index and input are mutually exclusive
group = parser.add_mutually_exclusive_group()
group.add_argument("-i", "--input", help="YAML file name")
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
if args.input and not os.path.isfile(args.input):
logging.warning("%s is not a valid file.", args.input)
sys.exit(-1)
if not args.output:
logging.error("No output file specified.")
sys.exit(-1)
if os.path.isfile(args.output):
logging.debug("%s already exists. Overwriting it.", args.output)
return args
def write_to_rstfile(content: str, filename: str) -> None:
"""Write the generated content into an RST file"""
logging.debug("Saving RST file to %s", filename)
with open(filename, "w", encoding="utf-8") as rst_file:
rst_file.write(content)
# pylint: disable=broad-exception-caught
def main() -> None:
"""Main function that reads the YAML files and generates the RST files"""
args = parse_arguments()
parser = YnlDocGenerator()
Annotation
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.