This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit a0479c86fba16915e7c6e82ab64427c0dc647ad6
Author: Eren Terzioglu <[email protected]>
AuthorDate: Tue Dec 17 13:35:00 2024 +0100

    tools: Add debug_info target to diagnostic system
---
 tools/parse_sysinfo.py | 135 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 135 insertions(+)

diff --git a/tools/parse_sysinfo.py b/tools/parse_sysinfo.py
new file mode 100644
index 000000000..428c1ac09
--- /dev/null
+++ b/tools/parse_sysinfo.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python3
+
+import argparse
+import os
+import re
+import sys
+
+
+def parse_information_from_header(file_path):
+    """
+    Parses the file that contains information about the host system
+    and NuttX configuration(sysinfo.h).
+
+    Args:
+        file_path (str): Path of the file to parse.
+
+    Returns:
+        dict: The contents parsed from file_path (sysinfo.h) header file.
+    """
+
+    VARIABLE_NAMES_REGEX = r"static\s+const\s+char\s+\**([A-Za-z0-9_]+)\s*"
+    VARIABLE_VALUES_REGEX = r'"([^"]*)"|{([^}]+)};'
+    result = {}
+    var_name_to_print_dict = {
+        "NUTTX_CFLAGS": "NuttX CFLAGS",
+        "NUTTX_CXXFLAGS": "NuttX CXXFLAGS",
+        "NUTTX_LDFLAGS": "NuttX LDFLAGS",
+        "NUTTX_CONFIG": "NuttX configuration options",
+        "SYSTEM_PATH": "Host system PATH",
+        "OS_VERSION": "Host system OS",
+        "INSTALLED_PACKAGES": "Host system installed packages",
+        "PYTHON_MODULES": "Host system installed python modules",
+        "ESPRESSIF_BOOTLOADER": "Espressif specific information:\n\nToolchain 
version",
+        "ESPRESSIF_TOOLCHAIN": "Toolchain version",
+        "ESPRESSIF_ESPTOOL": "Esptool version",
+        "ESPRESSIF_HAL": "HAL version",
+        "ESPRESSIF_CHIP_ID": "CHIP ID",
+        "ESPRESSIF_FLASH_ID": "Flash ID",
+        "ESPRESSIF_SECURITY_INFO": "Security information",
+        "ESPRESSIF_FLASH_STAT": "Flash status",
+        "ESPRESSIF_MAC_ADDR": "MAC address",
+    }
+
+    # Regular expression pattern to match array definition
+
+    keys_pattern = re.compile(VARIABLE_NAMES_REGEX, re.DOTALL)
+    values_pattern = re.compile(VARIABLE_VALUES_REGEX, re.DOTALL)
+
+    with open(file_path, "r") as file:
+        content = file.read()
+
+        # Match array definition using the regex
+
+        keys_array = keys_pattern.findall(content)
+        values_array = values_pattern.findall(content)
+
+        # Process values to print it prettier
+
+        for i in range(len(values_array)):
+            tmp_list = []
+            for y in range(len(values_array[i])):
+                tmp_str = values_array[i][y]
+                tmp_str = tmp_str.replace('"', "")
+                tmp_str = tmp_str.replace("\n  ", "", 1)
+                tmp_str = tmp_str.replace(",", "")
+
+                if tmp_str != "":
+                    tmp_list.append(tmp_str)
+
+            values_array[i] = tuple(tmp_list)
+
+        keys_values_to_return = [var_name_to_print_dict[x] for x in keys_array]
+        result = dict(zip(keys_values_to_return, values_array))
+
+    return result
+
+
+# Main #
+
+
+if __name__ == "__main__":
+    """
+    Main function for the script. This function is called when the script is
+    executed directly. It prints the output generated to stdout.
+
+    Required arguments:
+        nuttx_path: The path to the NuttX source directory.
+
+    Optional arguments:
+        The command line arguments. The available arguments are:
+            -h, --help:
+                        Show the help message and exit.
+            -f, --file <SYSINFO_FILE>:
+                        Provide the diagnostic file output(sysinfo.h).
+    """
+
+    # Generic arguments
+
+    parser = argparse.ArgumentParser(add_help=False)
+    parser.add_argument("nuttx_path", help="NuttX source directory path.")
+    parser.add_argument(
+        "-h",
+        "--help",
+        action="help",
+        default=argparse.SUPPRESS,
+        help="Show this help message and exit.",
+    )
+    parser.add_argument(
+        "-f",
+        "--file",
+        default="",
+        metavar=("SYSINFO_FILE"),
+        help="Provide the diagnostic file output(sysinfo.h).",
+    )
+    # Parse arguments
+
+    if len(sys.argv) == 1:
+        parser.print_help()
+        sys.exit(1)
+
+    args = parser.parse_args()
+    os.chdir(args.nuttx_path)
+
+    parsed_data = parse_information_from_header(args.file)
+
+    # Print the extracted name and values
+
+    if parsed_data:
+        for each_key in parsed_data.keys():
+            print("{}:".format(each_key))
+            for each_value in parsed_data[each_key]:
+                print("  {}".format(each_value))
+            print("")
+    else:
+        print("No matching array found.")

Reply via email to