| 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 compiled_file_system as compiled_fs | 9 import compiled_file_system as compiled_fs |
| 10 from file_system import FileNotFoundError | 10 from file_system import FileNotFoundError |
| 11 import third_party.json_schema_compiler.json_parse as json_parse | 11 import third_party.json_schema_compiler.json_parse as json_parse |
| 12 import third_party.json_schema_compiler.model as model | 12 import third_party.json_schema_compiler.model as model |
| 13 import third_party.json_schema_compiler.idl_schema as idl_schema | 13 import third_party.json_schema_compiler.idl_schema as idl_schema |
| 14 import third_party.json_schema_compiler.idl_parser as idl_parser | 14 import third_party.json_schema_compiler.idl_parser as idl_parser |
| 15 | 15 |
| 16 # Increment this version when there are changes to the data stored in any of | 16 # Increment this version when there are changes to the data stored in any of |
| 17 # the caches used by APIDataSource. This allows the cache to be invalidated | 17 # the caches used by APIDataSource. This allows the cache to be invalidated |
| 18 # without having to flush memcache on the production server. | 18 # without having to flush memcache on the production server. |
| 19 _VERSION = 8 | 19 _VERSION = 9 |
| 20 | 20 |
| 21 def _RemoveNoDocs(item): | 21 def _RemoveNoDocs(item): |
| 22 if json_parse.IsDict(item): | 22 if json_parse.IsDict(item): |
| 23 if item.get('nodoc', False): | 23 if item.get('nodoc', False): |
| 24 return True | 24 return True |
| 25 to_remove = [] | 25 to_remove = [] |
| 26 for key, value in item.items(): | 26 for key, value in item.items(): |
| 27 if _RemoveNoDocs(value): | 27 if _RemoveNoDocs(value): |
| 28 to_remove.append(key) | 28 to_remove.append(key) |
| 29 for k in to_remove: | 29 for k in to_remove: |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 callback_dict['parameters'].append(self._GenerateProperty(param)) | 160 callback_dict['parameters'].append(self._GenerateProperty(param)) |
| 161 if (len(callback_dict['parameters']) > 0): | 161 if (len(callback_dict['parameters']) > 0): |
| 162 callback_dict['parameters'][-1]['last'] = True | 162 callback_dict['parameters'][-1]['last'] = True |
| 163 return callback_dict | 163 return callback_dict |
| 164 | 164 |
| 165 def _GenerateProperties(self, properties): | 165 def _GenerateProperties(self, properties): |
| 166 return [self._GenerateProperty(v) for v in properties.values() | 166 return [self._GenerateProperty(v) for v in properties.values() |
| 167 if v.type_ != model.PropertyType.ADDITIONAL_PROPERTIES] | 167 if v.type_ != model.PropertyType.ADDITIONAL_PROPERTIES] |
| 168 | 168 |
| 169 def _GenerateProperty(self, property_): | 169 def _GenerateProperty(self, property_): |
| 170 # Make sure we generate property info for arrays, too. |
| 171 # TODO(kalman): what about choices? |
| 172 if property_.type_ == model.PropertyType.ARRAY: |
| 173 properties = property_.item_type.properties |
| 174 else: |
| 175 properties = property_.properties |
| 176 |
| 170 property_dict = { | 177 property_dict = { |
| 171 'name': property_.simple_name, | 178 'name': property_.simple_name, |
| 172 'optional': property_.optional, | 179 'optional': property_.optional, |
| 173 'description': self._FormatDescription(property_.description), | 180 'description': self._FormatDescription(property_.description), |
| 174 'properties': self._GenerateProperties(property_.properties), | 181 'properties': self._GenerateProperties(properties), |
| 175 'functions': self._GenerateFunctions(property_.functions), | 182 'functions': self._GenerateFunctions(property_.functions), |
| 176 'parameters': [], | 183 'parameters': [], |
| 177 'returns': None, | 184 'returns': None, |
| 178 'id': _CreateId(property_, 'property') | 185 'id': _CreateId(property_, 'property') |
| 179 } | 186 } |
| 180 for param in property_.params: | 187 for param in property_.params: |
| 181 property_dict['parameters'].append(self._GenerateProperty(param)) | 188 property_dict['parameters'].append(self._GenerateProperty(param)) |
| 182 if property_.returns: | 189 if property_.returns: |
| 183 property_dict['returns'] = self._GenerateProperty(property_.returns) | 190 property_dict['returns'] = self._GenerateProperty(property_.returns) |
| 184 if (property_.parent is not None and | 191 if (property_.parent is not None and |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 if self._disable_refs: | 427 if self._disable_refs: |
| 421 cache, ext = ( | 428 cache, ext = ( |
| 422 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else | 429 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else |
| 423 (self._json_cache_no_refs, '.json')) | 430 (self._json_cache_no_refs, '.json')) |
| 424 else: | 431 else: |
| 425 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else | 432 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else |
| 426 (self._json_cache, '.json')) | 433 (self._json_cache, '.json')) |
| 427 return self._GenerateHandlebarContext( | 434 return self._GenerateHandlebarContext( |
| 428 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), | 435 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), |
| 429 path) | 436 path) |
| OLD | NEW |