1#!/usr/bin/env python2 2# 3# Merge debugger YAML metadata files and output a merged JSON metadata file. 4# 5 6import os, sys, json, yaml 7import optparse 8 9if __name__ == '__main__': 10 parser = optparse.OptionParser() 11 parser.add_option('--output', dest='output', default=None, help='output JSON filename') 12 parser.add_option('--class-names', dest='class_names', help='YAML metadata for class names') 13 parser.add_option('--debug-commands', dest='debug_commands', help='YAML metadata for debug commands') 14 parser.add_option('--debug-errors', dest='debug_errors', help='YAML metadata for debug protocol error codes') 15 parser.add_option('--opcodes', dest='opcodes', help='YAML metadata for opcodes') 16 (opts, args) = parser.parse_args() 17 18 res = {} 19 def merge(fn): 20 with open(fn, 'rb') as f: 21 doc = yaml.load(f) 22 for k in doc.keys(): 23 res[k] = doc[k] 24 25 merge(opts.class_names) 26 merge(opts.debug_commands) 27 merge(opts.debug_errors) 28 merge(opts.opcodes) 29 30 with open(opts.output, 'wb') as f: 31 f.write(json.dumps(res, indent=4) + '\n') 32 print('Wrote merged debugger metadata to ' + str(opts.output)) 33