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

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

Issue 48263002: list apis by channel info, e.g. dev, stable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gerenate one new template, e.g. api_table Created 7 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
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 from operator import itemgetter 5 from operator import itemgetter
6 import os 6 import os
7 7
8 from third_party.json_schema_compiler.json_parse import Parse
9 import third_party.json_schema_compiler.model as model
10 import docs_server_utils as utils 8 import docs_server_utils as utils
9 from file_system import FileNotFoundError
11 10
12 def _GetAPICategory(api, documented_apis): 11 def _GetAPICategory(api, documented_apis):
13 name = api['name'] 12 name = api['name']
14 if (name.endswith('Private') or 13 if (name.endswith('Private') or
15 name not in documented_apis): 14 name not in documented_apis):
16 return 'private' 15 return 'private'
17 if name.startswith('experimental.'): 16 if name.startswith('experimental.'):
18 return 'experimental' 17 return 'experimental'
19 return 'chrome' 18 return 'chrome'
20 19
(...skipping 12 matching lines...) Expand all
33 - It has a dependency in _{api,manifest,permission}_features with an 32 - It has a dependency in _{api,manifest,permission}_features with an
34 "extension_types" property where either/both "extension"/"platform_app" 33 "extension_types" property where either/both "extension"/"platform_app"
35 values are present. 34 values are present.
36 """ 35 """
37 class Factory(object): 36 class Factory(object):
38 def __init__(self, 37 def __init__(self,
39 compiled_fs_factory, 38 compiled_fs_factory,
40 file_system, 39 file_system,
41 public_template_path, 40 public_template_path,
42 features_bundle, 41 features_bundle,
43 object_store_creator): 42 object_store_creator,
43 api_models,
44 availability_finder):
44 self._file_system = file_system 45 self._file_system = file_system
45 def NormalizePath(string): 46 def NormalizePath(string):
46 return string if string.endswith('/') else (string + '/') 47 return string if string.endswith('/') else (string + '/')
47 self._public_template_path = NormalizePath(public_template_path) 48 self._public_template_path = NormalizePath(public_template_path)
48 self._cache = compiled_fs_factory.Create(file_system, 49 self._cache = compiled_fs_factory.Create(file_system,
49 self._CollectDocumentedAPIs, 50 self._CollectDocumentedAPIs,
50 APIListDataSource) 51 APIListDataSource)
51 self._features_bundle = features_bundle 52 self._features_bundle = features_bundle
52 self._object_store_creator = object_store_creator 53 self._object_store_creator = object_store_creator
54 self._api_models = api_models
55 self._availability_finder = availability_finder
56
57 def _GetDocumentedApis(self):
58 return self._cache.GetFromFileListing(self._public_template_path).Get()
not at google - send to devlin 2013/11/05 01:02:02 there is an extra space after the "return" here.
hukun 2013/11/06 08:56:19 Done
59
60 def _GetApiFeatures(self):
61 return self._features_bundle.GetAPIFeatures()
53 62
54 def _CollectDocumentedAPIs(self, base_dir, files): 63 def _CollectDocumentedAPIs(self, base_dir, files):
55 def GetDocumentedAPIsForPlatform(names, platform): 64 def GetDocumentedAPIsForPlatform(names, platform):
56 public_templates = [] 65 public_templates = []
57 for root, _, files in self._file_system.Walk( 66 for root, _, files in self._file_system.Walk(
58 self._public_template_path + platform): 67 self._public_template_path + platform):
59 public_templates.extend( 68 public_templates.extend(
60 ('%s/%s' % (root, name)).lstrip('/') for name in files) 69 ('%s/%s' % (root, name)).lstrip('/') for name in files)
61 template_names = set(os.path.splitext(name)[0] 70 template_names = set(os.path.splitext(name)[0]
62 for name in public_templates) 71 for name in public_templates)
63 return [name.replace('_', '.') for name in template_names] 72 return [name.replace('_', '.') for name in template_names]
64 api_names = set(utils.SanitizeAPIName(name) for name in files) 73 api_names = set(utils.SanitizeAPIName(name) for name in files)
65 return { 74 return {
66 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), 75 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'),
67 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') 76 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions')
68 } 77 }
69 78
79 def GetAllNames(self):
80 api_features = self._GetApiFeatures().itervalues()
81 return [api['name'] for api in api_features]
82
70 def _GenerateAPIDict(self): 83 def _GenerateAPIDict(self):
71 documented_apis = self._cache.GetFromFileListing( 84 documented_apis = self._GetDocumentedApis()
72 self._public_template_path).Get()
73 api_features = self._features_bundle.GetAPIFeatures()
74 85
75 def FilterAPIs(platform): 86 def FilterAPIs(platform):
76 return (api for api in api_features.itervalues() 87 return (api for api
88 in self._features_bundle.GetAPIFeatures().itervalues()
77 if platform in api['platforms']) 89 if platform in api['platforms'])
78 90
91 def GetChannelInfo(api_name):
92 return self._availability_finder.GetApiAvailability(api_name)
93
94 def GetApiDescription(api_name):
95 try:
96 model = self._api_models.GetModel(api_name)
97 return model.Get().description
not at google - send to devlin 2013/11/05 01:02:02 likewise
hukun 2013/11/06 08:56:19 Done
98 except FileNotFoundError:
99 return ''
100
79 def MakeDictForPlatform(platform): 101 def MakeDictForPlatform(platform):
80 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } 102 platform_dict = { 'chrome': {'stable': [],'beta': [],
103 'dev': [],'trunk': [] }}
not at google - send to devlin 2013/11/05 01:02:02 I would prefer this be formatted like: platform_d
hukun 2013/11/06 08:56:19 Done
104 private_apis = []
105 experimental_apis = []
106 all_apis = []
107
81 for api in FilterAPIs(platform): 108 for api in FilterAPIs(platform):
82 category = _GetAPICategory(api, documented_apis[platform]) 109 category = _GetAPICategory(api, documented_apis[platform])
83 platform_dict[category].append(api) 110 api_name = api['name']
84 for category, apis in platform_dict.iteritems(): 111 if category == 'chrome':
85 platform_dict[category] = sorted(apis, key=itemgetter('name')) 112 all_apis.append(api)
86 utils.MarkLast(platform_dict[category]) 113 api['description'] = GetApiDescription(api_name)
114 channel = GetChannelInfo(api_name).channel
115 if channel == 'stable':
116 api['version'] = GetChannelInfo(api_name).version
not at google - send to devlin 2013/11/05 01:02:02 hold onto a reference to GetChannelInfo(api_name)
hukun 2013/11/06 08:56:19 Done
117 platform_dict[category][channel].append(api)
118 elif category == 'experimental':
119 api['description'] = GetApiDescription(api_name)
not at google - send to devlin 2013/11/05 01:02:02 you might as well just always assign api['descript
hukun 2013/11/06 08:56:19 E.g. musicManagerPrivate will be None returned by
120 experimental_apis.append(api)
121 all_apis.append(api)
122 elif category == 'private':
123 private_apis.append(api)
124
125 for category, apis_by_channel in platform_dict.iteritems():
not at google - send to devlin 2013/11/05 01:02:02 the only key in platform_dict at this point is 'ch
hukun 2013/11/06 08:56:19 Done
126 for channel, apis in apis_by_channel.iteritems():
127 if len(apis) == 0:
128 platform_dict[category][channel] = None
129 continue
130 platform_dict[category][channel] = sorted(apis,
131 key=itemgetter('name'))
132 utils.MarkLast(platform_dict[category][channel])
133
134 platform_dict.update({
135 'all_apis': sorted(all_apis, key=itemgetter('name')),
not at google - send to devlin 2013/11/05 01:02:02 just 'all'.
hukun 2013/11/06 08:56:19 Done
136 'private': sorted(private_apis,
137 key=itemgetter('name')),
138 'experimental': sorted(experimental_apis,
139 key=itemgetter('name')),
140 })
141 utils.MarkLast(platform_dict['all_apis'])
142 utils.MarkLast(platform_dict['private'])
143 utils.MarkLast(platform_dict['experimental'])
not at google - send to devlin 2013/11/05 01:02:02 And come to think of it, you should be able to wri
hukun 2013/11/06 08:56:19 Done
144
87 return platform_dict 145 return platform_dict
88
89 return { 146 return {
90 'apps': MakeDictForPlatform('apps'), 147 'apps': MakeDictForPlatform('apps'),
91 'extensions': MakeDictForPlatform('extensions') 148 'extensions': MakeDictForPlatform('extensions'),
92 } 149 }
93 150
94 def Create(self): 151 def Create(self):
95 return APIListDataSource(self, self._object_store_creator) 152 return APIListDataSource(self, self._object_store_creator)
96 153
97 def __init__(self, factory, object_store_creator): 154 def __init__(self, factory, object_store_creator):
98 self._factory = factory 155 self._factory = factory
99 self._object_store = object_store_creator.Create(APIListDataSource) 156 self._object_store = object_store_creator.Create(APIListDataSource)
100 157
101 def GetAllNames(self): 158 def GetAllNames(self):
102 apis = [] 159 data = self._object_store.Get('all_names').Get()
103 for platform in ['apps', 'extensions']: 160 if data is None:
104 for category in ['chrome', 'experimental', 'private']: 161 data = self._factory.GetAllNames()
105 apis.extend(self.get(platform).get(category)) 162 self._object_store.Set('all_names', data)
106 return [api['name'] for api in apis] 163 return data
107 164
108 def _GetCachedAPIData(self): 165 def _GetCachedAPIData(self):
109 data = self._object_store.Get('api_data').Get() 166 data = self._object_store.Get('api_data').Get()
110 if data is None: 167 if data is None:
111 data = self._factory._GenerateAPIDict() 168 data = self._factory._GenerateAPIDict()
112 self._object_store.Set('api_data', data) 169 self._object_store.Set('api_data', data)
113 return data 170 return data
114 171
115 def get(self, key): 172 def get(self, key):
116 return self._GetCachedAPIData().get(key) 173 return self._GetCachedAPIData().get(key)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698