From 9e385dedb99935df5ae7186401de301b8c385589 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 1 May 2021 18:23:58 -0700 Subject: [PATCH] port generate_configuration_table to argparse Removes a Pylint warning about using the deprecated optparse library. --- .gitlab-ci.yml | 8 ++--- ci/generate_configuration_table.py | 49 +++++++++++++----------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b35f71096..4c286db95 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -486,10 +486,10 @@ meta-data: stage: test script: - CONFIGURE_LOGS=Metadata/*/*/*/configure.log - - ci/generate_configuration_table.py --output-format html ${CONFIGURE_LOGS} > configuration-long-no-color.html - - ci/generate_configuration_table.py --output-format html --short ${CONFIGURE_LOGS} > configuration-short-no-color.html - - ci/generate_configuration_table.py --output-format html --short --color ${CONFIGURE_LOGS} > configuration-short-color-green-red.html - - ci/generate_configuration_table.py --output-format html --short --colors black:red ${CONFIGURE_LOGS} > configuration-short-color-red-only.html + - ci/generate_configuration_table.py --output-format HTML ${CONFIGURE_LOGS} > configuration-long-no-color.html + - ci/generate_configuration_table.py --output-format HTML --short ${CONFIGURE_LOGS} > configuration-short-no-color.html + - ci/generate_configuration_table.py --output-format HTML --short --color ${CONFIGURE_LOGS} > configuration-short-color-green-red.html + - ci/generate_configuration_table.py --output-format HTML --short --colors black:red ${CONFIGURE_LOGS} > configuration-short-color-red-only.html artifacts: paths: - configuration-*.html diff --git a/ci/generate_configuration_table.py b/ci/generate_configuration_table.py index 04e8b7618..3be81d349 100755 --- a/ci/generate_configuration_table.py +++ b/ci/generate_configuration_table.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -from optparse import OptionParser +from argparse import ArgumentParser import os import json import sys @@ -11,31 +11,24 @@ def main(): "JSON", "HTML", ] - parser = OptionParser(usage="usage: %prog [options] files...") - parser.description = "Generate a table of the Graphviz compile " \ - "configuration for different platforms from files generated by the " \ - "./configure command." - parser.add_option("-c", "--color", action="store_const", - dest="colors", const = "green:red", default=None, - help="Color output using default coloring. Yes is colored \ - green and No is colored red") - parser.add_option("--colors", action="store", - dest="colors", default=None, - help="Color output using specifed COLORS. The format is :") - parser.add_option("-s", "--short", action="store_true", - dest="short", default=False, - help="Output only Yes or No") - parser.add_option("--output-format", action="store", - dest="output_format", default="JSON", - help="Set output format. Supported formats are " + - " and ".join(supported_output_formats)) + parser = ArgumentParser(description="Generate a table of the Graphviz compile " + "configuration for different platforms from files " + "generated by the ./configure command.") + parser.add_argument("--color", "-c", action="store_const", + dest="colors", const="green:red", + help="Color output using default coloring. Yes is " + "colored green and No is colored red") + parser.add_argument("--colors", + help="Color output using specified COLORS. The format is " + ":") + parser.add_argument("--short", "-s", action="store_true", + help="Output only Yes or No") + parser.add_argument("--output-format", default="JSON", + choices=supported_output_formats, + help="Set output format.") + parser.add_argument("filename", nargs='*', help="Configuration log to read") - (opts, args) = parser.parse_args() - - if opts.output_format.upper() not in supported_output_formats: - sys.stderr.write(f"Error: {opts.output_format} output format is not supported\n") - parser.print_help(file=sys.stderr) - sys.exit(1) + opts = parser.parse_args() if opts.colors is None: styles = { @@ -64,7 +57,7 @@ def main(): component_names = {} platforms = [] - for filename in args: + for filename in opts.filename: os_path = os.path.dirname(filename) os_version_id = os.path.basename(os_path) os_id = os.path.basename(os.path.dirname(os_path)) @@ -91,9 +84,9 @@ def main(): component_names[section_name].append(component_name) table[section_name][component_name][platform] = component_value - if opts.output_format.upper() == "JSON": + if opts.output_format == "JSON": print(json.dumps(table, indent=4)) - elif opts.output_format.upper() == "HTML": + elif opts.output_format == "HTML": colspan = len(platforms) + 1 indent = "" print(f"{indent}") -- 2.40.0