| 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 526 |
| 527 json_files = read_json_files_from_gypi(gypi_file) | 527 json_files = read_json_files_from_gypi(gypi_file) |
| 528 | 528 |
| 529 cpp_code = CC_HEADER | 529 cpp_code = CC_HEADER |
| 530 found_invalid_config = False | 530 found_invalid_config = False |
| 531 for json_file in json_files: | 531 for json_file in json_files: |
| 532 with open(json_file, 'r') as f: | 532 with open(json_file, 'r') as f: |
| 533 json_text = f.read() | 533 json_text = f.read() |
| 534 try: | 534 try: |
| 535 config = json.loads(json_text) | 535 config = json.loads(json_text) |
| 536 except ValueError: | 536 except ValueError, e: |
| 537 print >> sys.stderr, "%s: error parsing JSON" % json_file | 537 print >> sys.stderr, "%s: error parsing JSON: %s" % (json_file, e) |
| 538 raise | 538 found_invalid_config = True |
| 539 continue |
| 539 if 'monitored_domain' not in config: | 540 if 'monitored_domain' not in config: |
| 540 print >> sys.stderr, '%s: no monitored_domain found' % json_file | 541 print >> sys.stderr, '%s: no monitored_domain found' % json_file |
| 541 found_invalid_config = True | 542 found_invalid_config = True |
| 542 continue | 543 continue |
| 543 domain = config['monitored_domain'] | 544 domain = config['monitored_domain'] |
| 544 if not domain_is_whitelisted(domain): | 545 if not domain_is_whitelisted(domain): |
| 545 print >> sys.stderr, ('%s: monitored_domain "%s" not in whitelist' % | 546 print >> sys.stderr, ('%s: monitored_domain "%s" not in whitelist' % |
| 546 (json_file, domain)) | 547 (json_file, domain)) |
| 547 found_invalid_config = True | 548 found_invalid_config = True |
| 548 continue | 549 continue |
| 549 cpp_code += " // " + json_file + ":\n" | 550 cpp_code += " // " + json_file + ":\n" |
| 550 cpp_code += quote_and_wrap_text(json_text) + ",\n" | 551 cpp_code += quote_and_wrap_text(json_text) + ",\n" |
| 551 cpp_code += "\n" | 552 cpp_code += "\n" |
| 552 cpp_code += CC_FOOTER | 553 cpp_code += CC_FOOTER |
| 553 | 554 |
| 554 if found_invalid_config: | 555 if found_invalid_config: |
| 555 return 1 | 556 return 1 |
| 556 | 557 |
| 557 with open(cpp_file, 'wb') as f: | 558 with open(cpp_file, 'wb') as f: |
| 558 f.write(cpp_code) | 559 f.write(cpp_code) |
| 559 | 560 |
| 560 return 0 | 561 return 0 |
| 561 | 562 |
| 562 | 563 |
| 563 if __name__ == '__main__': | 564 if __name__ == '__main__': |
| 564 sys.exit(main()) | 565 sys.exit(main()) |
| OLD | NEW |