| OLD | NEW | 
|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be | 
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. | 
| 4 | 4 | 
| 5 import os.path | 5 import os.path | 
| 6 import sys | 6 import sys | 
| 7 import optparse | 7 import optparse | 
| 8 import collections | 8 import collections | 
| 9 import functools | 9 import functools | 
| 10 import re | 10 import re | 
|  | 11 import copy | 
| 11 try: | 12 try: | 
| 12     import json | 13     import json | 
| 13 except ImportError: | 14 except ImportError: | 
| 14     import simplejson as json | 15     import simplejson as json | 
| 15 | 16 | 
| 16 # Path handling for libraries and templates | 17 # Path handling for libraries and templates | 
| 17 # Paths have to be normalized because Jinja uses the exact template path to | 18 # Paths have to be normalized because Jinja uses the exact template path to | 
| 18 # determine the hash used in the cache filename, and we need a pre-caching step | 19 # determine the hash used in the cache filename, and we need a pre-caching step | 
| 19 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 20 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 
| 20 # module is imported, and relative if executed directly. | 21 # module is imported, and relative if executed directly. | 
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 461 | 462 | 
| 462 def main(): | 463 def main(): | 
| 463     jinja_dir, config_file, config = read_config() | 464     jinja_dir, config_file, config = read_config() | 
| 464 | 465 | 
| 465     protocol = Protocol() | 466     protocol = Protocol() | 
| 466     protocol.json_api = {"domains": []} | 467     protocol.json_api = {"domains": []} | 
| 467     protocol.generate_domains = read_protocol_file(config.protocol.path, protoco
     l.json_api) | 468     protocol.generate_domains = read_protocol_file(config.protocol.path, protoco
     l.json_api) | 
| 468     protocol.imported_domains = read_protocol_file(config.imported.path, protoco
     l.json_api) if config.imported else [] | 469     protocol.imported_domains = read_protocol_file(config.imported.path, protoco
     l.json_api) if config.imported else [] | 
| 469     patch_full_qualified_refs(protocol) | 470     patch_full_qualified_refs(protocol) | 
| 470     calculate_imports_and_exports(config, protocol) | 471     calculate_imports_and_exports(config, protocol) | 
|  | 472 | 
|  | 473     for domain in protocol.json_api["domains"]: | 
|  | 474         if "events" in domain: | 
|  | 475             for event in domain["events"]: | 
|  | 476                 event_type = dict() | 
|  | 477                 event_type["description"] = "Wrapper for notification params" | 
|  | 478                 event_type["type"] = "object" | 
|  | 479                 event_type["id"] = to_title_case(event["name"]) + "Notification" | 
|  | 480                 if "parameters" in event: | 
|  | 481                     event_type["properties"] = copy.deepcopy(event["parameters"]
     ) | 
|  | 482                 if "types" not in domain: | 
|  | 483                     domain["types"] = list() | 
|  | 484                 domain["types"].append(event_type) | 
|  | 485 | 
| 471     create_type_definitions(protocol, "::".join(config.imported.namespace) if co
     nfig.imported else "") | 486     create_type_definitions(protocol, "::".join(config.imported.namespace) if co
     nfig.imported else "") | 
| 472 | 487 | 
| 473     if not config.exported and len(protocol.exported_domains): | 488     if not config.exported and len(protocol.exported_domains): | 
| 474         sys.stderr.write("Domains [%s] are exported, but config is missing expor
     t entry\n\n" % ", ".join(protocol.exported_domains)) | 489         sys.stderr.write("Domains [%s] are exported, but config is missing expor
     t entry\n\n" % ", ".join(protocol.exported_domains)) | 
| 475         exit(1) | 490         exit(1) | 
| 476 | 491 | 
| 477     if not os.path.exists(config.protocol.output): | 492     if not os.path.exists(config.protocol.output): | 
| 478         os.mkdir(config.protocol.output) | 493         os.mkdir(config.protocol.output) | 
| 479     if len(protocol.exported_domains) and not os.path.exists(config.exported.out
     put): | 494     if len(protocol.exported_domains) and not os.path.exists(config.exported.out
     put): | 
| 480         os.mkdir(config.exported.output) | 495         os.mkdir(config.exported.output) | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 580     if up_to_date: | 595     if up_to_date: | 
| 581         sys.exit() | 596         sys.exit() | 
| 582 | 597 | 
| 583     for file_name, content in outputs.iteritems(): | 598     for file_name, content in outputs.iteritems(): | 
| 584         out_file = open(file_name, "w") | 599         out_file = open(file_name, "w") | 
| 585         out_file.write(content) | 600         out_file.write(content) | 
| 586         out_file.close() | 601         out_file.close() | 
| 587 | 602 | 
| 588 | 603 | 
| 589 main() | 604 main() | 
| OLD | NEW | 
|---|