]> granicus.if.org Git - graphviz/commitdiff
port generate_configuration_table to argparse
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 2 May 2021 01:23:58 +0000 (18:23 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 8 May 2021 03:52:13 +0000 (20:52 -0700)
Removes a Pylint warning about using the deprecated optparse library.

.gitlab-ci.yml
ci/generate_configuration_table.py

index b35f71096519d603257df9a7646cefcc50c941f7..4c286db95deb9491df67f3a07e6fece299a9f2b7 100644 (file)
@@ -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
index 04e8b7618418f39504a5af8a6644623106c0244d..3be81d349d52e286c907fade389dff64e1bbec55 100755 (executable)
@@ -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 <Yes-color>:<No-color>")
-  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 "
+                      "<Yes-color>:<No-color>")
+  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}<!DOCTYPE html>")