tools/docs/get_feat.py

Source file repositories/reference/linux-study-clean/tools/docs/get_feat.py

File Facts

System
Linux kernel
Corpus path
tools/docs/get_feat.py
Extension
.py
Size
7650 bytes
Lines
226
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.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env python3
# pylint: disable=R0902,R0911,R0912,R0914,R0915
# Copyright(c) 2025: Mauro Carvalho Chehab <mchehab@kernel.org>.
# SPDX-License-Identifier: GPL-2.0


"""
Parse the Linux Feature files and produce a ReST book.
"""

import argparse
import os
import subprocess
import sys

from pprint import pprint

LIB_DIR = "../../tools/lib/python"
SRC_DIR = os.path.dirname(os.path.realpath(__file__))

sys.path.insert(0, os.path.join(SRC_DIR, LIB_DIR))

from feat.parse_features import ParseFeature                # pylint: disable=C0413

SRCTREE = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../..")
DEFAULT_DIR = "Documentation/features"


class GetFeature:
    """Helper class to parse feature parsing parameters"""

    @staticmethod
    def get_current_arch():
        """Detects the current architecture"""

        proc = subprocess.run(["uname", "-m"], check=True,
                              capture_output=True, text=True)

        arch = proc.stdout.strip()
        if arch in ["x86_64", "i386"]:
            arch = "x86"
        elif arch == "s390x":
            arch = "s390"

        return arch

    def run_parser(self, args):
        """Execute the feature parser"""

        feat = ParseFeature(args.directory, args.debug, args.enable_fname)
        data = feat.parse()

        if args.debug > 2:
            pprint(data)

        return feat

    def run_rest(self, args):
        """
        Generate tables in ReST format. Three types of tables are
        supported, depending on the calling arguments:

        - neither feature nor arch is passed: generates a full matrix;
        - arch provided: generates a table of supported tables for the
          guiven architecture, eventually filtered by feature;
        - only feature provided: generates a table with feature details,
          showing what architectures it is implemented.
        """

        feat = self.run_parser(args)

Annotation

Implementation Notes