scripts/doc_to_xls.py: split code into a XLS conversion and main()
PATCH 1/1 scripts/doc_to_xls.py: split code into a XLS conversion and main()
From: Mauro Carvalho Chehab <[email protected]>
Such change allows using the code on some other python script that would be converting IGT doc test documentation into XLS files.
--- scripts/doc_to_xls.py | 113 ++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 48 deletions(-)
scripts/doc_to_xls.py +65 -48
@@ -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)
Signature · 1 line
2.43.2
Hi Mauro,
Quoted 6 lines · Mauro Carvalho Chehab
From: Mauro Carvalho Chehab <[email protected]>
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 <[email protected]>
While I am not python expert, I checked your code with pylint, there are some warnings:
************* Module doc_to_xlsscripts/doc_to_xls.py:109:0: C0305: Trailing newlines (trailing-newlines)scripts/doc_to_xls.py:25:0: C0413: Import "import argparse" should be placed at the top of the module (wrong-import-position) scripts/doc_to_xls.py:27:0: E0401: Unable to import 'openpyxl' (import-error)scripts/doc_to_xls.py:27:0: C0413: Import "from openpyxl import Workbook" should be placed at the top of the module (wrong-import-position) scripts/doc_to_xls.py:28:0: E0401: Unable to import 'openpyxl.utils' (import-error)scripts/doc_to_xls.py:28:0: C0413: Import "from openpyxl.utils import get_column_letter" should be placed at the top of the module (wrong-import-position) scripts/doc_to_xls.py:29:0: E0401: Unable to import 'openpyxl.styles' (import-error)scripts/doc_to_xls.py:29:0: C0413: Import "from openpyxl.styles import Font" should be placed at the top of the module (wrong-import-position) scripts/doc_to_xls.py:31:0: C0413: Import "from test_list import TestList" should be placed at the top of the module (wrong-import-position) scripts/doc_to_xls.py:86:0: C0116: Missing function or method docstring (missing-function-docstring)
After move of import statements just after Copyright comments, there are:
************* Module doc_to_xlsscripts/doc_to_xls.py:109:0: C0305: Trailing newlines (trailing-newlines) scripts/doc_to_xls.py:1:0: C0114: Missing module docstring (missing-module-docstring) scripts/doc_to_xls.py:19:0: W0105: String statement has no effect (pointless-string-statement) scripts/doc_to_xls.py:86:0: C0116: Missing function or method docstring (missing-function-docstring)
First one imho could be ignored (one newline at end of file), I do not know if others are also to be ignored?
Regards,
Kamil
Quoted 140 lines
--- scripts/doc_to_xls.py | 113 ++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 48 deletions(-)scripts/doc_to_xls.py +65
-48@@ -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)Signature · 1 line
2.43.2