[PATCH i-g-t] scripts/doc_to_xls.py: split code into a XLS conversion and main()

Mauro Carvalho Chehab mauro.chehab at linux.intel.com
Mon Mar 11 13:11:16 UTC 2024


From: Mauro Carvalho Chehab <mchehab at kernel.org>

Such change allows using the code on some other python script that
would be converting IGT doc test documentation into XLS files.

Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
---
 scripts/doc_to_xls.py | 113 ++++++++++++++++++++++++------------------
 1 file changed, 65 insertions(+), 48 deletions(-)

diff --git a/scripts/doc_to_xls.py b/scripts/doc_to_xls.py
index 12c0223920ae..a4b1d9d8be1b 100755
--- a/scripts/doc_to_xls.py
+++ b/scripts/doc_to_xls.py
@@ -30,63 +30,80 @@ from openpyxl.styles import Font
 
 from test_list import TestList
 
-parser = argparse.ArgumentParser(description=__doc__,
-                                 formatter_class = argparse.RawDescriptionHelpFormatter,
-                                 epilog = EPILOG)
-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.")
+def tests_to_xls(tests, fname):
+    """
+    Convert an array of IGT documentation tests into a XLS file
+    """
 
-parse_args = parser.parse_args()
+    wb = Workbook()
+    ws = None
 
-tests = []
-for config_file in parse_args.config:
-    # Implemented tests
-    tests.append(TestList(config_file, parse_args.include_plan))
+    expand_fields = {
+        "GPU excluded platform": "blocklist "
+    }
 
-wb = Workbook()
-ws = None
+    for row in range(len(tests)):
+        test = tests[row]
+        sheet_name = test.title
 
-expand_fields = {
-    "GPU excluded platform": "blocklist "
-}
+        if not ws:
+            ws = wb.active
+            ws.title = sheet_name
+        else:
+            ws = wb.create_sheet(sheet_name)
 
-for row in range(len(tests)):
-    test = tests[row]
-    sheet_name = test.title
+        sheet = test.get_spreadsheet(expand_fields)
 
-    if not ws:
-        ws = wb.active
-        ws.title = sheet_name
-    else:
-        ws = wb.create_sheet(sheet_name)
-
-    sheet = test.get_spreadsheet(expand_fields)
-
-    max_length = []
-    for col in range(len(sheet[row])):
-        max_length.append(0)
-
-    for row in range(len(sheet)):
+        max_length = []
         for col in range(len(sheet[row])):
-            c = ws.cell(row = row + 1, column = col + 1, value = sheet[row][col])
-            if row == 0:
-                c.font = Font(bold=True)
+            max_length.append(0)
 
-            if len(sheet[row][col]) > max_length[col]:
-                max_length[col] = len(sheet[row][col])
+        for row in range(len(sheet)):
+            for col in range(len(sheet[row])):
+                c = ws.cell(row = row + 1, column = col + 1, value = sheet[row][col])
+                if row == 0:
+                    c.font = Font(bold=True)
 
-    # Estimate column length
-    for col in range(len(sheet[0])):
-        column = get_column_letter(col + 1)
+                if len(sheet[row][col]) > max_length[col]:
+                    max_length[col] = len(sheet[row][col])
 
-        adjusted_width = (max_length[col] + 2) * 1.2
-        ws.column_dimensions[column].width = adjusted_width
+        # Estimate column length
+        for col in range(len(sheet[0])):
+            column = get_column_letter(col + 1)
 
-    # Turn on auto-filter
-    ws.auto_filter.ref = ws.dimensions
+            adjusted_width = (max_length[col] + 2) * 1.2
+            ws.column_dimensions[column].width = adjusted_width
+
+        # Turn on auto-filter
+        ws.auto_filter.ref = ws.dimensions
+
+    wb.save(fname)
+
+######
+# Main
+######
+
+def main():
+
+    parser = argparse.ArgumentParser(description=__doc__,
+                                     formatter_class = argparse.RawDescriptionHelpFormatter,
+                                     epilog = EPILOG)
+    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))
+
+    tests_to_xls(tests, fname = parse_args.xls)
+
+if __name__ == '__main__':
+    main()
 
-wb.save(parse_args.xls)
-- 
2.43.2



More information about the igt-dev mailing list