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

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

Issue 10827063: Extensions Docs Server: Pull info from _permission_features.json (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 8
9 from handlebar_dict_generator import HandlebarDictGenerator 9 from handlebar_dict_generator import HandlebarDictGenerator
10 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater 10 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
11 import third_party.json_schema_compiler.model as model 11 import third_party.json_schema_compiler.model as model
12 import third_party.json_schema_compiler.idl_schema as idl_schema 12 import third_party.json_schema_compiler.idl_schema as idl_schema
13 import third_party.json_schema_compiler.idl_parser as idl_parser 13 import third_party.json_schema_compiler.idl_parser as idl_parser
14 14
15 class APIDataSource(object): 15 class APIDataSource(object):
16 """This class fetches and loads JSON APIs from the FileSystem passed in with 16 """This class fetches and loads JSON APIs from the FileSystem passed in with
17 |cache_builder|, so the APIs can be plugged into templates. 17 |cache_builder|, so the APIs can be plugged into templates.
18 """ 18 """
19 def __init__(self, cache_builder, base_path): 19 def __init__(self, cache_builder, file_system, base_path):
20 self._file_system = file_system
20 self._json_cache = cache_builder.build(self._LoadJsonAPI) 21 self._json_cache = cache_builder.build(self._LoadJsonAPI)
21 self._idl_cache = cache_builder.build(self._LoadIdlAPI) 22 self._idl_cache = cache_builder.build(self._LoadIdlAPI)
22 self._base_path = base_path 23 self._base_path = base_path
23 24
24 def _LoadJsonAPI(self, api): 25 def _LoadJsonAPI(self, api):
25 generator = HandlebarDictGenerator( 26 generator = HandlebarDictGenerator(
26 json.loads(json_comment_eater.Nom(api))[0]) 27 json.loads(json_comment_eater.Nom(api))[0])
27 return generator.Generate() 28 return generator.Generate()
28 29
29 def _LoadIdlAPI(self, api): 30 def _LoadIdlAPI(self, api):
30 idl = idl_parser.IDLParser().ParseData(api) 31 idl = idl_parser.IDLParser().ParseData(api)
31 generator = HandlebarDictGenerator(idl_schema.IDLSchema(idl).process()[0]) 32 generator = HandlebarDictGenerator(idl_schema.IDLSchema(idl).process()[0])
32 return generator.Generate() 33 return generator.Generate()
33 34
35 def _GetChannel(self, path):
not at google - send to devlin 2012/07/30 12:43:23 This is getting the Feature, not the Channel ("cha
cduvall 2012/07/30 19:08:29 Done.
36 path = path.replace('experimental_', '')
37 try:
38 perms = json.loads(json_comment_eater.Nom(
39 self._file_system.ReadSingle(
40 self._base_path + '/_permission_features.json')))
not at google - send to devlin 2012/07/30 12:43:23 Could you put the loaded JSON in a cache (like the
cduvall 2012/07/30 19:08:29 Done.
41 return perms.get(path, None)
42 except:
43 return None
44
34 def __getitem__(self, key): 45 def __getitem__(self, key):
35 return self.get(key) 46 return self.get(key)
36 47
37 def get(self, key): 48 def get(self, key):
38 path, ext = os.path.splitext(key) 49 path, ext = os.path.splitext(key)
50 api_dict = { 'perms': self._GetChannel(path) }
not at google - send to devlin 2012/07/30 12:43:23 no need to abbr perms
cduvall 2012/07/30 19:08:29 Done.
39 unix_name = model.UnixName(path) 51 unix_name = model.UnixName(path)
40 json_path = unix_name + '.json' 52 json_path = unix_name + '.json'
41 idl_path = unix_name + '.idl' 53 idl_path = unix_name + '.idl'
42 try: 54 try:
43 return self._json_cache.GetFromFile(self._base_path + '/' + json_path) 55 api_dict.update(
56 self._json_cache.GetFromFile(self._base_path + '/' + json_path))
57 return api_dict
not at google - send to devlin 2012/07/30 12:43:23 looks like this is a job for a helper method...
cduvall 2012/07/30 19:08:29 Done.
44 except Exception: 58 except Exception:
45 try: 59 try:
46 return self._idl_cache.GetFromFile(self._base_path + '/' + idl_path) 60 api_dict.update(
61 self._idl_cache.GetFromFile(self._base_path + '/' + idl_path))
62 return api_dict
47 except Exception as e: 63 except Exception as e:
48 logging.warn(e) 64 logging.warn(e)
49 return None 65 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698