Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / chromevox / tools / generate_test_messages.py
blob17d4088ca34c138f037bb52e5a37dcaf48c841ea
1 #!/usr/bin/env python
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 '''Generates test_messages.js from an extension message json file.'''
9 import optparse
10 import sys
12 def Die(message):
13 '''Prints an error message and exit the program.'''
14 print >>sys.stderr, message
15 sys.exit(1)
18 # Tempalte for the test_messages.js.
19 _JS_TEMPLATE = '''// GENERATED FROM %(in_file)s
21 goog.provide('cvox.TestMessages');
23 cvox.TestMessages = %(json)s;
24 '''
27 def main():
28 parser = optparse.OptionParser(description=__doc__)
29 parser.add_option('-o', '--output_file', action='store',
30 metavar='SPEC',
31 help=('Where to output the generated deps file.'))
32 options, args = parser.parse_args()
33 if options.output_file is None:
34 Die('Output file not specified')
35 if len(args) != 1:
36 Die('Exactly one input file must be specified')
37 in_file_name = args[0]
38 with open(in_file_name) as in_file:
39 json = in_file.read().strip()
40 with open(options.output_file, 'w') as out_file:
41 out_file.write(_JS_TEMPLATE % {'in_file': in_file_name, 'json': json})
44 if __name__ == '__main__':
45 main()