[PATCH i-g-t] scripts/xls_to_doc.py: use a main() function

Kamil Konieczny kamil.konieczny at linux.intel.com
Tue Mar 12 16:19:20 UTC 2024


Hi Mauro,
On 2024-03-11 at 14:02:20 +0100, Mauro Carvalho Chehab wrote:
> From: Mauro Carvalho Chehab <mchehab at kernel.org>
> 
> 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.

pylint found some problems:

pylint scripts/xls_to_doc.py
************* Module xls_to_doc
scripts/xls_to_doc.py:68:0: W0311: Bad indentation. Found 20 spaces, expected 16 (bad-indentation)
scripts/xls_to_doc.py:69:0: W0311: Bad indentation. Found 20 spaces, expected 16 (bad-indentation)
scripts/xls_to_doc.py:70:0: W0311: Bad indentation. Found 24 spaces, expected 20 (bad-indentation)
scripts/xls_to_doc.py:68:29: R1733: Unnecessary dictionary index lookup, use 'item' instead (unnecessary-dict-index-lookup)

-----------------------------------
Your code has been rated at 9.82/10

Regards,
Kamil

> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab at kernel.org>
> ---
>  scripts/xls_to_doc.py | 47 +++++++++++++++++++++++--------------------
>  1 file changed, 25 insertions(+), 22 deletions(-)
> 
> diff --git a/scripts/xls_to_doc.py b/scripts/xls_to_doc.py
> index 510ab54276ba..fdf98105cd4b 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')
> +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()
> +    parse_args = parser.parse_args()
>  
> -fill_test = FillTests(parse_args.config)
> +    fill_test = FillTests(parse_args.config)
>  
> -if "sheets" not in parse_args:
> -    parse_args.sheets = None
> +    if "sheets" not in parse_args:
> +        parse_args.sheets = None
>  
> -fill_test.parse_spreadsheet(parse_args.xls, parse_args.sheets)
> +    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)
> +    ## 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)
>  
> -fill_test.update_test_files(parse_args)
> +if __name__ == '__main__':
> +    main()
> -- 
> 2.43.2
> 


More information about the igt-dev mailing list