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

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: updated with the new simplejson 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 logging 6 import logging
8 import os 7 import os
9 8
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 = 3 19 _VERSION = 4
21 20
22 def _RemoveNoDocs(item): 21 def _RemoveNoDocs(item):
23 if type(item) == dict: 22 if json_parse.IsDict(item):
24 if item.get('nodoc', False): 23 if item.get('nodoc', False):
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 = []
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 self._idl_cache, 326 self._idl_cache,
328 self._json_cache_no_refs, 327 self._json_cache_no_refs,
329 self._idl_cache_no_refs, 328 self._idl_cache_no_refs,
330 self._names_cache, 329 self._names_cache,
331 self._idl_names_cache, 330 self._idl_names_cache,
332 self._base_path, 331 self._base_path,
333 samples, 332 samples,
334 disable_refs) 333 disable_refs)
335 334
336 def _LoadPermissions(self, json_str): 335 def _LoadPermissions(self, json_str):
337 return json.loads(json_comment_eater.Nom(json_str)) 336 return json_parse.Parse(json_str)
338 337
339 def _LoadJsonAPI(self, api, disable_refs): 338 def _LoadJsonAPI(self, api, disable_refs):
340 return _JSCModel( 339 return _JSCModel(
341 json.loads(json_comment_eater.Nom(api))[0], 340 json_parse.Parse(api)[0],
342 self._ref_resolver_factory.Create() if not disable_refs else None, 341 self._ref_resolver_factory.Create() if not disable_refs else None,
343 disable_refs).ToDict() 342 disable_refs).ToDict()
344 343
345 def _LoadIdlAPI(self, api, disable_refs): 344 def _LoadIdlAPI(self, api, disable_refs):
346 idl = idl_parser.IDLParser().ParseData(api) 345 idl = idl_parser.IDLParser().ParseData(api)
347 return _JSCModel( 346 return _JSCModel(
348 idl_schema.IDLSchema(idl).process()[0], 347 idl_schema.IDLSchema(idl).process()[0],
349 self._ref_resolver_factory.Create() if not disable_refs else None, 348 self._ref_resolver_factory.Create() if not disable_refs else None,
350 disable_refs).ToDict() 349 disable_refs).ToDict()
351 350
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 path = model.UnixName(path.replace('experimental_', '')) 396 path = model.UnixName(path.replace('experimental_', ''))
398 for filename in ['_permission_features.json', '_manifest_features.json']: 397 for filename in ['_permission_features.json', '_manifest_features.json']:
399 api_perms = self._GetPermsFromFile(filename).get(path, None) 398 api_perms = self._GetPermsFromFile(filename).get(path, None)
400 if api_perms is not None: 399 if api_perms is not None:
401 break 400 break
402 if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'): 401 if api_perms and api_perms['channel'] in ('trunk', 'dev', 'beta'):
403 api_perms[api_perms['channel']] = True 402 api_perms[api_perms['channel']] = True
404 return api_perms 403 return api_perms
405 404
406 def _GenerateHandlebarContext(self, handlebar_dict, path): 405 def _GenerateHandlebarContext(self, handlebar_dict, path):
407 return_dict = { 406 handlebar_dict['permissions'] = self._GetFeature(path)
408 'permissions': self._GetFeature(path), 407 handlebar_dict['samples'] = _LazySamplesGetter(path, self._samples)
409 'samples': _LazySamplesGetter(path, self._samples) 408 return handlebar_dict
410 }
411 return_dict.update(handlebar_dict)
412 return return_dict
413 409
414 def _GetAsSubdirectory(self, name): 410 def _GetAsSubdirectory(self, name):
415 if name.startswith('experimental_'): 411 if name.startswith('experimental_'):
416 parts = name[len('experimental_'):].split('_', 1) 412 parts = name[len('experimental_'):].split('_', 1)
417 parts[1] = 'experimental_%s' % parts[1] 413 parts[1] = 'experimental_%s' % parts[1]
418 return '/'.join(parts) 414 return '/'.join(parts)
419 return name.replace('_', '/', 1) 415 return name.replace('_', '/', 1)
420 416
421 def get(self, key): 417 def get(self, key):
422 if key.endswith('.html') or key.endswith('.json') or key.endswith('.idl'): 418 if key.endswith('.html') or key.endswith('.json') or key.endswith('.idl'):
423 path, ext = os.path.splitext(key) 419 path, ext = os.path.splitext(key)
424 else: 420 else:
425 path = key 421 path = key
426 unix_name = model.UnixName(path) 422 unix_name = model.UnixName(path)
427 idl_names = self._idl_names_cache.GetFromFileListing(self._base_path) 423 idl_names = self._idl_names_cache.GetFromFileListing(self._base_path)
428 names = self._names_cache.GetFromFileListing(self._base_path) 424 names = self._names_cache.GetFromFileListing(self._base_path)
429 if unix_name not in names and self._GetAsSubdirectory(unix_name) in names: 425 if unix_name not in names and self._GetAsSubdirectory(unix_name) in names:
430 unix_name = self._GetAsSubdirectory(unix_name) 426 unix_name = self._GetAsSubdirectory(unix_name)
431 427
432 if self._disable_refs: 428 if self._disable_refs:
433 cache, ext = ( 429 cache, ext = (
434 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else 430 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else
435 (self._json_cache_no_refs, '.json')) 431 (self._json_cache_no_refs, '.json'))
436 else: 432 else:
437 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else 433 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else
438 (self._json_cache, '.json')) 434 (self._json_cache, '.json'))
439 return self._GenerateHandlebarContext( 435 return self._GenerateHandlebarContext(
440 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), 436 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)),
441 path) 437 path)
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698