OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 """Takes the JSON files in components/domain_reliability/baked_in_configs and | 7 """Takes the JSON files in components/domain_reliability/baked_in_configs and |
8 encodes their contents as an array of C strings that gets compiled in to Chrome | 8 encodes their contents as an array of C strings that gets compiled in to Chrome |
9 and loaded at runtime.""" | 9 and loaded at runtime.""" |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 | 72 |
73 def main(): | 73 def main(): |
74 if len(sys.argv) < 3: | 74 if len(sys.argv) < 3: |
75 print >> sys.stderr, ('Usage: %s <JSON files...> <output C++ file>' % | 75 print >> sys.stderr, ('Usage: %s <JSON files...> <output C++ file>' % |
76 sys.argv[0]) | 76 sys.argv[0]) |
77 print >> sys.stderr, sys.modules[__name__].__doc__ | 77 print >> sys.stderr, sys.modules[__name__].__doc__ |
78 return 1 | 78 return 1 |
79 | 79 |
80 cpp_code = CC_HEADER | 80 cpp_code = CC_HEADER |
81 cpp_file = sys.argv[-1] | |
82 for json_file in sys.argv[1:-1]: | 81 for json_file in sys.argv[1:-1]: |
83 with open(json_file, 'r') as f: | 82 with open(json_file, 'r') as f: |
84 json_text = f.read() | 83 json_text = f.read() |
85 config = json.loads(json_text) | 84 config = json.loads(json_text) |
86 if 'monitored_domain' not in config: | 85 if 'monitored_domain' not in config: |
87 print >> sys.stderr ('%s: no monitored_domain found' % json_file) | 86 print >> sys.stderr ('%s: no monitored_domain found' % json_file) |
88 return 1 | 87 return 1 |
89 domain = config['monitored_domain'] | 88 domain = config['monitored_domain'] |
90 if not domain_is_whitelisted(domain): | 89 if not domain_is_whitelisted(domain): |
91 print >> sys.stderr ('%s: monitored_domain "%s" not in whitelist' % | 90 print >> sys.stderr ('%s: monitored_domain "%s" not in whitelist' % |
92 (json_file, domain)) | 91 (json_file, domain)) |
93 return 1 | 92 return 1 |
94 cpp_code += " // " + json_file + ":\n" | 93 cpp_code += " // " + json_file + ":\n" |
95 cpp_code += quote_and_wrap_text(json_text) + ",\n" | 94 cpp_code += quote_and_wrap_text(json_text) + ",\n" |
96 cpp_code += "\n" | 95 cpp_code += "\n" |
97 cpp_code += CC_FOOTER | 96 cpp_code += CC_FOOTER |
98 | 97 |
99 with open(cpp_file, 'wb') as f: | 98 with open(sys.argv[-1], 'wb') as f: |
100 f.write(cpp_code) | 99 f.write(cpp_code) |
101 | 100 |
102 return 0 | 101 return 0 |
103 | 102 |
104 | 103 |
105 if __name__ == '__main__': | 104 if __name__ == '__main__': |
106 sys.exit(main()) | 105 sys.exit(main()) |
OLD | NEW |