From 36c9cb435d4957a7cbb255aece22f6f1c3125d43 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Wed, 13 Mar 2024 08:56:04 +0100 Subject: scripts/xls_to_doc.py: use a main() function Move the main code to a function, called only when the script is executed directly from command line. That allows the method to be re-used by other scripts if needed. No functional changes. Signed-off-by: Mauro Carvalho Chehab Reviewed-by: Katarzyna Piecielska --- scripts/xls_to_doc.py | 61 +++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'scripts') diff --git a/scripts/xls_to_doc.py b/scripts/xls_to_doc.py index 510ab5427..fdf98105c 100755 --- a/scripts/xls_to_doc.py +++ b/scripts/xls_to_doc.py @@ -293,32 +293,35 @@ class FillTests(TestList): # Main ###### -parser = argparse.ArgumentParser(description=__doc__, - formatter_class = argparse.ArgumentDefaultsHelpFormatter, - argument_default = argparse.SUPPRESS, - epilog = EPILOG) -parser.add_argument("--config", required = True, - help="JSON file describing the test plan template") -parser.add_argument("--xls", required = True, - help="Input XLS file.") -parser.add_argument("--sheets", nargs = "*", - help="Input only some specific sheets from the XLS file.") -parser.add_argument('--ignore-lists',action='store_false', default=True, help='Ignore fields that are updated via test lists') - -parse_args = parser.parse_args() - -fill_test = FillTests(parse_args.config) - -if "sheets" not in parse_args: - parse_args.sheets = None - -fill_test.parse_spreadsheet(parse_args.xls, parse_args.sheets) - -## DEBUG: remove it later on -with open("fill_test.json", "w", encoding='utf8') as write_file: - json.dump(fill_test.tests, write_file, indent = 4) -with open("doc.json", "w", encoding='utf8') as write_file: - json.dump(fill_test.doc, write_file, indent = 4) - - -fill_test.update_test_files(parse_args) +def main(): + parser = argparse.ArgumentParser(description=__doc__, + formatter_class = argparse.ArgumentDefaultsHelpFormatter, + argument_default = argparse.SUPPRESS, + epilog = EPILOG) + parser.add_argument("--config", required = True, + help="JSON file describing the test plan template") + parser.add_argument("--xls", required = True, + help="Input XLS file.") + parser.add_argument("--sheets", nargs = "*", + help="Input only some specific sheets from the XLS file.") + parser.add_argument('--ignore-lists',action='store_false', default=True, help='Ignore fields that are updated via test lists') + + parse_args = parser.parse_args() + + fill_test = FillTests(parse_args.config) + + if "sheets" not in parse_args: + parse_args.sheets = None + + fill_test.parse_spreadsheet(parse_args.xls, parse_args.sheets) + + ## DEBUG: remove it later on + with open("fill_test.json", "w", encoding='utf8') as write_file: + json.dump(fill_test.tests, write_file, indent = 4) + with open("doc.json", "w", encoding='utf8') as write_file: + json.dump(fill_test.doc, write_file, indent = 4) + + fill_test.update_test_files(parse_args) + +if __name__ == '__main__': + main() -- cgit v1.2.3