[igt-dev] [PATCH i-g-t 6/6] scripts/doc_to_xls.py: add an script to generate a doc spreadsheet

Kamil Konieczny kamil.konieczny at linux.intel.com
Fri May 26 12:20:47 UTC 2023


Hi Mauro,

On 2023-05-22 at 16:22:01 +0200, Mauro Carvalho Chehab wrote:
> From: Mauro Carvalho Chehab <mchehab at kernel.org>
> 
> Add a script to convert documentation to a spreadsheet.
> 
> The logic here can read multiple config files. It will retrieve
> documentation from the files that are configured inside each input
> JSON file.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>

imho it is worth to add examples of useage here or as comments
in source code.

Acked-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>

Regards,
Kamil

> ---
>  scripts/doc_to_xls.py | 70 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 70 insertions(+)
>  create mode 100755 scripts/doc_to_xls.py
> 
> diff --git a/scripts/doc_to_xls.py b/scripts/doc_to_xls.py
> new file mode 100755
> index 000000000000..1f33c1828ceb
> --- /dev/null
> +++ b/scripts/doc_to_xls.py
> @@ -0,0 +1,70 @@
> +#!/usr/bin/env python3
> +# pylint: disable=C0103, C0200
> +# SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +
> +## Copyright (C) 2023    Intel Corporation                 ##
> +## Author: Mauro Carvalho Chehab <mchehab at kernel.org>      ##
> +##                                                         ##
> +## Allow keeping inlined test documentation and validate   ##
> +## if the documentation is kept updated.                   ##
> +
> +"""Maintain test plan and test implementation documentation on IGT."""
> +
> +import argparse
> +
> +from openpyxl import Workbook
> +
> +from test_list import TestList
> +
> +parser = argparse.ArgumentParser(description = "Print formatted kernel documentation to stdout.",
> +                                 formatter_class = argparse.ArgumentDefaultsHelpFormatter,
> +                                 epilog = 'If no action specified, assume --rest.')
> +parser.add_argument("--config", required = True,  nargs='+',
> +                    help="JSON file describing the test plan template")
> +parser.add_argument("--include-plan", action="store_true",
> +                    help="Include test plans, if any.")
> +parser.add_argument("--xls", required = True,
> +                    help="Output XLS file.")
> +
> +parse_args = parser.parse_args()
> +
> +tests = []
> +for config_file in parse_args.config:
> +    # Implemented tests
> +    tests.append(TestList(config_file, parse_args.include_plan))
> +
> +wb = Workbook()
> +ws = None
> +
> +for row in range(len(tests)):
> +    test = tests[row]
> +    sheet_name = test.title
> +
> +    if not ws:
> +        ws = wb.active
> +        ws.title = sheet_name
> +    else:
> +        ws = wb.create_sheet(sheet_name)
> +
> +    sheet = test.get_spreadsheet()
> +
> +    max_length = []
> +    for col in range(len(sheet[row])):
> +        max_length.append(0)
> +
> +    for row in range(len(sheet)):
> +        for col in range(len(sheet[row])):
> +            ws.cell(row = row + 1, column = col + 1, value = sheet[row][col])
> +            if len(sheet[row][col]) > max_length[col]:
> +                max_length[col] = len(sheet[row][col])
> +
> +    col = 0
> +    for c in ws.columns:
> +        column = c[0].column_letter
> +
> +        adjusted_width = (max_length[col] + 2) * 1.2
> +        ws.column_dimensions[column].width = adjusted_width
> +
> +        col += 1
> +
> +wb.save(parse_args.xls)
> -- 
> 2.40.1
> 


More information about the igt-dev mailing list