Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 copy | 5 import copy |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 import third_party.json_schema_compiler.model as model | 9 import third_party.json_schema_compiler.model as model |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 'properties': self._GenerateProperties(self._namespace.properties) | 62 'properties': self._GenerateProperties(self._namespace.properties) |
| 63 } | 63 } |
| 64 except Exception as e: | 64 except Exception as e: |
| 65 logging.info(e) | 65 logging.info(e) |
| 66 | 66 |
| 67 def _GenerateType(self, type_): | 67 def _GenerateType(self, type_): |
| 68 type_dict = { | 68 type_dict = { |
| 69 'name': type_.name, | 69 'name': type_.name, |
| 70 'description': type_.description, | 70 'description': type_.description, |
| 71 'properties': self._GenerateProperties(type_.properties), | 71 'properties': self._GenerateProperties(type_.properties), |
| 72 'functions': self._GenerateFunctions(type_.functions) | 72 'functions': self._GenerateFunctions(type_.functions), |
| 73 'events': map(self._GenerateEvent, type_.events.values()) | |
|
not at google - send to devlin
2012/07/20 02:04:54
types have events? whoa.
chebert
2012/07/21 19:40:31
ChromeSetting is the only type where I have seen t
| |
| 73 } | 74 } |
| 74 self._RenderTypeInformation(type_, type_dict) | 75 self._RenderTypeInformation(type_, type_dict) |
| 75 return type_dict | 76 return type_dict |
| 76 | 77 |
| 77 def _GenerateFunctions(self, functions): | 78 def _GenerateFunctions(self, functions): |
| 78 return map(self._GenerateFunction, functions.values()) | 79 return map(self._GenerateFunction, functions.values()) |
| 79 | 80 |
| 80 def _GenerateFunction(self, function): | 81 def _GenerateFunction(self, function): |
| 81 function_dict = { | 82 function_dict = { |
| 82 'name': function.name, | 83 'name': function.name, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 97 'name': event.name, | 98 'name': event.name, |
| 98 'description': event.description, | 99 'description': event.description, |
| 99 'parameters': map(self._GenerateProperty, event.params) | 100 'parameters': map(self._GenerateProperty, event.params) |
| 100 } | 101 } |
| 101 if len(event_dict['parameters']) > 0: | 102 if len(event_dict['parameters']) > 0: |
| 102 event_dict['parameters'][-1]['last'] = True | 103 event_dict['parameters'][-1]['last'] = True |
| 103 return event_dict | 104 return event_dict |
| 104 | 105 |
| 105 def _GenerateCallback(self, callback): | 106 def _GenerateCallback(self, callback): |
| 106 if not callback: | 107 if not callback: |
| 107 return {} | 108 return None |
| 108 callback_dict = { | 109 callback_dict = { |
| 109 'name': 'callback', | 110 'name': 'callback', |
| 110 'description': callback.description, | 111 'description': callback.description, |
| 111 'simple_type': {'simple_type': 'function'}, | 112 'simple_type': {'simple_type': 'function'}, |
| 112 'optional': callback.optional, | 113 'optional': callback.optional, |
| 113 'parameters': [] | 114 'parameters': [] |
| 114 } | 115 } |
| 115 for param in callback.params: | 116 for param in callback.params: |
| 116 callback_dict['parameters'].append(self._GenerateProperty(param)) | 117 callback_dict['parameters'].append(self._GenerateProperty(param)) |
| 117 if (len(callback_dict['parameters']) > 0): | 118 if (len(callback_dict['parameters']) > 0): |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 139 return property_dict | 140 return property_dict |
| 140 | 141 |
| 141 def _RenderTypeInformation(self, property_, dst_dict): | 142 def _RenderTypeInformation(self, property_, dst_dict): |
| 142 if property_.type_ == model.PropertyType.CHOICES: | 143 if property_.type_ == model.PropertyType.CHOICES: |
| 143 dst_dict['choices'] = map(self._GenerateProperty, | 144 dst_dict['choices'] = map(self._GenerateProperty, |
| 144 property_.choices.values()) | 145 property_.choices.values()) |
| 145 # We keep track of which is last for knowing when to add "or" between | 146 # We keep track of which is last for knowing when to add "or" between |
| 146 # choices in templates. | 147 # choices in templates. |
| 147 if len(dst_dict['choices']) > 0: | 148 if len(dst_dict['choices']) > 0: |
| 148 dst_dict['choices'][-1]['last'] = True | 149 dst_dict['choices'][-1]['last'] = True |
| 150 elif property_.type_ == model.PropertyType.ADDITIONAL_PROPERTIES: | |
| 151 dst_dict['additional_properties'] = True | |
| 149 elif property_.type_ == model.PropertyType.REF: | 152 elif property_.type_ == model.PropertyType.REF: |
| 150 dst_dict['link'] = _GetLinkToRefType(self._namespace.name, | 153 dst_dict['link'] = _GetLinkToRefType(self._namespace.name, |
| 151 property_.ref_type) | 154 property_.ref_type) |
| 152 elif property_.type_ == model.PropertyType.ARRAY: | 155 elif property_.type_ == model.PropertyType.ARRAY: |
| 153 dst_dict['array'] = self._GenerateProperty(property_.item_type) | 156 dst_dict['array'] = self._GenerateProperty(property_.item_type) |
| 154 elif property_.type_ == model.PropertyType.ENUM: | 157 elif property_.type_ == model.PropertyType.ENUM: |
| 155 dst_dict['enum_values'] = [] | 158 dst_dict['enum_values'] = [] |
| 156 for enum_value in property_.enum_values: | 159 for enum_value in property_.enum_values: |
| 157 dst_dict['enum_values'].append({'name': enum_value}) | 160 dst_dict['enum_values'].append({'name': enum_value}) |
| 158 if len(dst_dict['enum_values']) > 0: | 161 if len(dst_dict['enum_values']) > 0: |
| 159 dst_dict['enum_values'][-1]['last'] = True | 162 dst_dict['enum_values'][-1]['last'] = True |
| 160 else: | 163 else: |
| 161 dst_dict['simple_type'] = {'simple_type': property_.type_.name.lower()} | 164 dst_dict['simple_type'] = {'simple_type': property_.type_.name.lower()} |
| OLD | NEW |