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

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: Tests! Created 8 years, 2 months 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 = 0 19 _VERSION = 1
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):
25 return True 24 return True
26 for key, value in item.items(): 25 for key, value in item.items():
27 if _RemoveNoDocs(value): 26 if _RemoveNoDocs(value):
28 del item[key] 27 del item[key]
29 elif type(item) == list: 28 elif type(item) == list:
30 for i in item: 29 for i in item:
31 if _RemoveNoDocs(i): 30 if _RemoveNoDocs(i):
32 item.remove(i) 31 item.remove(i)
33 return False 32 return False
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 254
256 def Create(self, request): 255 def Create(self, request):
257 return APIDataSource(self._permissions_cache, 256 return APIDataSource(self._permissions_cache,
258 self._json_cache, 257 self._json_cache,
259 self._idl_cache, 258 self._idl_cache,
260 self._idl_names_cache, 259 self._idl_names_cache,
261 self._base_path, 260 self._base_path,
262 self._samples_factory.Create(request)) 261 self._samples_factory.Create(request))
263 262
264 def _LoadPermissions(self, json_str): 263 def _LoadPermissions(self, json_str):
265 return json.loads(json_comment_eater.Nom(json_str)) 264 return json_parse.Parse(json_str)
266 265
267 def _LoadJsonAPI(self, api): 266 def _LoadJsonAPI(self, api):
268 return _JscModel(json.loads(json_comment_eater.Nom(api))[0]) 267 return _JscModel(json_parse.Parse(api)[0])
269 268
270 def _LoadIdlAPI(self, api): 269 def _LoadIdlAPI(self, api):
271 idl = idl_parser.IDLParser().ParseData(api) 270 idl = idl_parser.IDLParser().ParseData(api)
272 return _JscModel(idl_schema.IDLSchema(idl).process()[0]) 271 return _JscModel(idl_schema.IDLSchema(idl).process()[0])
273 272
274 def _GetIDLNames(self, apis): 273 def _GetIDLNames(self, apis):
275 return [model.UnixName(os.path.splitext(api.split('/')[-1])[0]) 274 return [model.UnixName(os.path.splitext(api.split('/')[-1])[0])
276 for api in apis if api.endswith('.idl')] 275 for api in apis if api.endswith('.idl')]
277 276
278 def __init__(self, 277 def __init__(self,
(...skipping 24 matching lines...) Expand all
303 path = model.UnixName(path.replace('experimental_', '')) 302 path = model.UnixName(path.replace('experimental_', ''))
304 for filename in ['_permission_features.json', '_manifest_features.json']: 303 for filename in ['_permission_features.json', '_manifest_features.json']:
305 api_perms = self._GetPermsFromFile(filename).get(path, None) 304 api_perms = self._GetPermsFromFile(filename).get(path, None)
306 if api_perms is not None: 305 if api_perms is not None:
307 break 306 break
308 if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'): 307 if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'):
309 api_perms[api_perms['channel']] = True 308 api_perms[api_perms['channel']] = True
310 return api_perms 309 return api_perms
311 310
312 def _GenerateHandlebarContext(self, handlebar, path): 311 def _GenerateHandlebarContext(self, handlebar, path):
313 return_dict = { 312 return_dict = handlebar.ToDict()
314 'permissions': self._GetFeature(path), 313 return_dict['permissions'] = self._GetFeature(path)
315 'samples': _LazySamplesGetter(path, self._samples) 314 return_dict['samples'] = _LazySamplesGetter(path, self._samples)
316 }
317 return_dict.update(handlebar.ToDict())
318 return return_dict 315 return return_dict
319 316
320 def __getitem__(self, key): 317 def __getitem__(self, key):
321 return self.get(key) 318 return self.get(key)
322 319
323 def get(self, key): 320 def get(self, key):
324 path, ext = os.path.splitext(key) 321 path, ext = os.path.splitext(key)
325 unix_name = model.UnixName(path) 322 unix_name = model.UnixName(path)
326 idl_names = self._idl_names_cache.GetFromFileListing(self._base_path) 323 idl_names = self._idl_names_cache.GetFromFileListing(self._base_path)
327 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else 324 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else
328 (self._json_cache, '.json')) 325 (self._json_cache, '.json'))
329 return self._GenerateHandlebarContext( 326 return self._GenerateHandlebarContext(
330 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), 327 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)),
331 path) 328 path)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698