]> granicus.if.org Git - graphviz/commitdiff
Add JSON output
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sun, 7 Jun 2020 14:38:20 +0000 (16:38 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sat, 13 Jun 2020 06:16:54 +0000 (08:16 +0200)
ci/generate-configuration-table.py

index 6afcf0d032b92901c3095392baedbd8d70a4a813..c8954fd1b0085dcfe34a37eaf2d53b733719a2c9 100755 (executable)
@@ -3,8 +3,13 @@
 
 from optparse import OptionParser
 import os
+import json
+import sys
 
 def main():
+    supported_output_formats = [
+        'JSON',
+    ]
     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 ' \
@@ -12,9 +17,18 @@ def main():
     parser.add_option('-v', '--verbose', action='store_true',
                       dest='verbose', default=False,
                       help='Log info about what is going on')
+    parser.add_option('--output-format', action='store',
+                      dest='output_format', default='JSON',
+                      help='Set output format. Supported formats are ' +
+                      ' and '.join(supported_output_formats))
 
     (opts, args) = parser.parse_args()
 
+    if opts.output_format.upper() not in supported_output_formats:
+        print('Error:', opts.output_format, 'output format is not supported', file=sys.stderr)
+        parser.print_help(file=sys.stderr)
+        exit(1)
+
     table = {}
     table_sections = []
     component_names = {}
@@ -45,6 +59,9 @@ def main():
                         component_names[section_name].append(component_name)
                     table[section_name][component_name][platform] = component_value
 
+    if opts.output_format.upper() == 'JSON':
+        print(json.dumps(table, indent=4))
+
 # Python trick to get a main routine
 if __name__ == "__main__":
     main()