Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 11079010: Extensions Docs Server: Preserve JSON declaration order in extensions documentation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more efficient ordered_dict Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 json
7 import os 6 import os
8 7
9 from docs_server_utils import GetLinkToRefType 8 from docs_server_utils import GetLinkToRefType
10 import compiled_file_system as compiled_fs 9 import compiled_file_system as compiled_fs
11 from file_system import FileNotFoundError 10 from file_system import FileNotFoundError
12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater 11 import third_party.json_schema_compiler.json_parse as json_parse
13 import third_party.json_schema_compiler.model as model 12 import third_party.json_schema_compiler.model as model
14 import third_party.json_schema_compiler.idl_schema as idl_schema 13 import third_party.json_schema_compiler.idl_schema as idl_schema
15 import third_party.json_schema_compiler.idl_parser as idl_parser 14 import third_party.json_schema_compiler.idl_parser as idl_parser
16 15
17 # 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
18 # 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
19 # without having to flush memcache on the production server. 18 # without having to flush memcache on the production server.
20 _VERSION = 2 19 _VERSION = 3
21 20
22 def _RemoveNoDocs(item): 21 def _RemoveNoDocs(item):
23 if type(item) == dict: 22 if isinstance(item, (dict, json_parse.OrderedDict)):
24 if item.get('nodoc', False): 23 if item.get('nodoc', False):
not at google - send to devlin 2012/11/16 18:45:56 might be cleaner exposing like json_parse.IsDict(.
cduvall 2012/11/17 01:55:12 Done.
25 return True 24 return True
26 to_remove = [] 25 to_remove = []
27 for key, value in item.items(): 26 for key, value in item.items():
28 if _RemoveNoDocs(value): 27 if _RemoveNoDocs(value):
29 to_remove.append(key) 28 to_remove.append(key)
30 for k in to_remove: 29 for k in to_remove:
31 del item[k] 30 del item[k]
32 elif type(item) == list: 31 elif type(item) == list:
33 to_remove = [] 32 to_remove = []
34 for i in item: 33 for i in item:
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 266
268 def Create(self, request): 267 def Create(self, request):
269 return APIDataSource(self._permissions_cache, 268 return APIDataSource(self._permissions_cache,
270 self._json_cache, 269 self._json_cache,
271 self._idl_cache, 270 self._idl_cache,
272 self._idl_names_cache, 271 self._idl_names_cache,
273 self._base_path, 272 self._base_path,
274 self._samples_factory.Create(request)) 273 self._samples_factory.Create(request))
275 274
276 def _LoadPermissions(self, json_str): 275 def _LoadPermissions(self, json_str):
277 return json.loads(json_comment_eater.Nom(json_str)) 276 return json_parse.Parse(json_str)
278 277
279 def _LoadJsonAPI(self, api): 278 def _LoadJsonAPI(self, api):
280 return _JscModel(json.loads(json_comment_eater.Nom(api))[0]) 279 return _JscModel(json_parse.Parse(api)[0])
281 280
282 def _LoadIdlAPI(self, api): 281 def _LoadIdlAPI(self, api):
283 idl = idl_parser.IDLParser().ParseData(api) 282 idl = idl_parser.IDLParser().ParseData(api)
284 return _JscModel(idl_schema.IDLSchema(idl).process()[0]) 283 return _JscModel(idl_schema.IDLSchema(idl).process()[0])
285 284
286 def _GetIDLNames(self, apis): 285 def _GetIDLNames(self, apis):
287 return [model.UnixName(os.path.splitext(api.split('/')[-1])[0]) 286 return [model.UnixName(os.path.splitext(api.split('/')[-1])[0])
288 for api in apis if api.endswith('.idl')] 287 for api in apis if api.endswith('.idl')]
289 288
290 def __init__(self, 289 def __init__(self,
(...skipping 24 matching lines...) Expand all
315 path = model.UnixName(path.replace('experimental_', '')) 314 path = model.UnixName(path.replace('experimental_', ''))
316 for filename in ['_permission_features.json', '_manifest_features.json']: 315 for filename in ['_permission_features.json', '_manifest_features.json']:
317 api_perms = self._GetPermsFromFile(filename).get(path, None) 316 api_perms = self._GetPermsFromFile(filename).get(path, None)
318 if api_perms is not None: 317 if api_perms is not None:
319 break 318 break
320 if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'): 319 if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'):
321 api_perms[api_perms['channel']] = True 320 api_perms[api_perms['channel']] = True
322 return api_perms 321 return api_perms
323 322
324 def _GenerateHandlebarContext(self, handlebar, path): 323 def _GenerateHandlebarContext(self, handlebar, path):
325 return_dict = { 324 return_dict = handlebar.ToDict()
326 'permissions': self._GetFeature(path), 325 return_dict['permissions'] = self._GetFeature(path)
327 'samples': _LazySamplesGetter(path, self._samples) 326 return_dict['samples'] = _LazySamplesGetter(path, self._samples)
328 }
329 return_dict.update(handlebar.ToDict())
330 return return_dict 327 return return_dict
331 328
332 def __getitem__(self, key): 329 def __getitem__(self, key):
333 return self.get(key) 330 return self.get(key)
334 331
335 def get(self, key): 332 def get(self, key):
336 path, ext = os.path.splitext(key) 333 path, ext = os.path.splitext(key)
337 unix_name = model.UnixName(path) 334 unix_name = model.UnixName(path)
338 idl_names = self._idl_names_cache.GetFromFileListing(self._base_path) 335 idl_names = self._idl_names_cache.GetFromFileListing(self._base_path)
339 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else 336 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else
340 (self._json_cache, '.json')) 337 (self._json_cache, '.json'))
341 return self._GenerateHandlebarContext( 338 return self._GenerateHandlebarContext(
342 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), 339 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)),
343 path) 340 path)
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | tools/json_schema_compiler/json_parse.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698