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

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: fix last issue 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_list_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 from operator import itemgetter 5 from operator import itemgetter
6 import os 6 import os
7 import posixpath 7 import posixpath
8 8
9 from branch_utility import ChannelInfo
9 from svn_constants import PUBLIC_TEMPLATE_PATH 10 from svn_constants import PUBLIC_TEMPLATE_PATH
10 import docs_server_utils as utils 11 import docs_server_utils as utils
12 from file_system import FileNotFoundError
11 13
12 def _GetAPICategory(api, documented_apis): 14 def _GetAPICategory(api_name, documented_apis):
13 name = api['name'] 15 if (api_name.endswith('Private') or
14 if (name.endswith('Private') or 16 api_name not in documented_apis):
15 name not in documented_apis):
16 return 'private' 17 return 'private'
17 if name.startswith('experimental.'): 18 if api_name.startswith('experimental.'):
18 return 'experimental' 19 return 'experimental'
19 return 'chrome' 20 return 'chrome'
20 21
21 22
22 class APIListDataSource(object): 23 class APIListDataSource(object):
23 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs 24 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs
24 for extensions and apps that are used in the api_index.html, 25 for extensions and apps that are used in the api_index.html,
25 experimental.html, and private_apis.html pages. 26 experimental.html, and private_apis.html pages.
26 27
27 An API is considered listable if it is listed in _api_features.json, 28 An API is considered listable if it is listed in _api_features.json,
28 it has a corresponding HTML file in the public template path, and one of 29 it has a corresponding HTML file in the public template path, and one of
29 the following conditions is met: 30 the following conditions is met:
30 - It has no "dependencies" or "extension_types" properties in _api_features 31 - It has no "dependencies" or "extension_types" properties in _api_features
31 - It has an "extension_types" property in _api_features with either/both 32 - It has an "extension_types" property in _api_features with either/both
32 "extension"/"platform_app" values present. 33 "extension"/"platform_app" values present.
33 - It has a dependency in _{api,manifest,permission}_features with an 34 - It has a dependency in _{api,manifest,permission}_features with an
34 "extension_types" property where either/both "extension"/"platform_app" 35 "extension_types" property where either/both "extension"/"platform_app"
35 values are present. 36 values are present.
36 """ 37 """
37 class Factory(object): 38 class Factory(object):
38 def __init__(self, 39 def __init__(self,
39 compiled_fs_factory, 40 compiled_fs_factory,
40 file_system, 41 file_system,
41 features_bundle, 42 features_bundle,
42 object_store_creator): 43 object_store_creator,
44 api_models,
45 availability_finder):
43 self._file_system = file_system 46 self._file_system = file_system
44 self._cache = compiled_fs_factory.Create(file_system, 47 self._cache = compiled_fs_factory.Create(file_system,
45 self._CollectDocumentedAPIs, 48 self._CollectDocumentedAPIs,
46 APIListDataSource) 49 APIListDataSource)
47 self._features_bundle = features_bundle 50 self._features_bundle = features_bundle
48 self._object_store_creator = object_store_creator 51 self._object_store_creator = object_store_creator
52 self._api_models = api_models
53 self._availability_finder = availability_finder
54
55 def _GetDocumentedApis(self):
56 return self._cache.GetFromFileListing(self._public_template_path).Get()
49 57
50 def _CollectDocumentedAPIs(self, base_dir, files): 58 def _CollectDocumentedAPIs(self, base_dir, files):
51 def GetDocumentedAPIsForPlatform(names, platform): 59 def GetDocumentedAPIsForPlatform(names, platform):
52 public_templates = [] 60 public_templates = []
53 for root, _, files in self._file_system.Walk(posixpath.join( 61 for root, _, files in self._file_system.Walk(posixpath.join(
54 PUBLIC_TEMPLATE_PATH, platform)): 62 PUBLIC_TEMPLATE_PATH, platform)):
55 public_templates.extend( 63 public_templates.extend(
56 ('%s/%s' % (root, name)).lstrip('/') for name in files) 64 ('%s/%s' % (root, name)).lstrip('/') for name in files)
57 template_names = set(os.path.splitext(name)[0] 65 template_names = set(os.path.splitext(name)[0]
58 for name in public_templates) 66 for name in public_templates)
59 return [name.replace('_', '.') for name in template_names] 67 return [name.replace('_', '.') for name in template_names]
60 api_names = set(utils.SanitizeAPIName(name) for name in files) 68 api_names = set(utils.SanitizeAPIName(name) for name in files)
61 return { 69 return {
62 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), 70 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'),
63 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') 71 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions')
64 } 72 }
65 73
66 def _GenerateAPIDict(self): 74 def _GenerateAPIDict(self):
67 documented_apis = self._cache.GetFromFileListing( 75 documented_apis = self._cache.GetFromFileListing(
68 PUBLIC_TEMPLATE_PATH).Get() 76 PUBLIC_TEMPLATE_PATH).Get()
69 api_features = self._features_bundle.GetAPIFeatures().Get()
70 77
71 def FilterAPIs(platform): 78 def GetChannelInfo(api_name):
72 return (api for api in api_features.itervalues() 79 return self._availability_finder.GetApiAvailability(api_name)
73 if platform in api['platforms']) 80
81 def GetApiDescription(model):
82 try:
83 return model.Get().description if model.Get() else ''
84 except FileNotFoundError:
85 return ''
86
87 def GetApiPlatform(api_name):
88 feature = self._features_bundle.GetAPIFeatures().Get()[api_name]
89 return feature['platforms']
74 90
75 def MakeDictForPlatform(platform): 91 def MakeDictForPlatform(platform):
76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } 92 platform_dict = {
77 for api in FilterAPIs(platform): 93 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []}
78 if api['name'] in documented_apis[platform]: 94 }
79 category = _GetAPICategory(api, documented_apis[platform]) 95 private_apis = []
80 platform_dict[category].append(api) 96 experimental_apis = []
81 for category, apis in platform_dict.iteritems(): 97 all_apis = []
82 platform_dict[category] = sorted(apis, key=itemgetter('name')) 98 for api_name, api_model in self._api_models.IterModels():
83 utils.MarkLast(platform_dict[category]) 99 api = {'name': api_name}
100 api['description'] = GetApiDescription(api_model)
101 api['platforms'] = GetApiPlatform(api_name)
not at google - send to devlin 2013/11/13 17:43:30 you can write this slightly nicer like api = {
hukun 2013/11/13 18:04:00 Done
102 category = _GetAPICategory(api_name, documented_apis[platform])
103 if category == 'chrome':
104 channel_info = GetChannelInfo(api_name)
105 channel = channel_info.channel
106 if channel == 'stable':
107 api['version'] = channel_info.version
108 platform_dict[category][channel].append(api)
109 all_apis.append(api)
110 elif category == 'experimental':
111 experimental_apis.append(api)
112 all_apis.append(api)
113 elif category == 'private':
114 private_apis.append(api)
115
116 for channel, apis_by_channel in platform_dict['chrome'].iteritems():
117 apis_by_channel = sorted(apis_by_channel, key=itemgetter('name'))
118 utils.MarkLast(apis_by_channel)
119 platform_dict['chrome'][channel] = apis_by_channel
120
121 for key, apis in (('all', all_apis),
122 ('private', private_apis),
123 ('experimental', experimental_apis)):
124 apis = sorted(apis, key=itemgetter('name'))
125 utils.MarkLast(apis)
126 platform_dict[key] = apis
84 return platform_dict 127 return platform_dict
85
86 return { 128 return {
87 'apps': MakeDictForPlatform('apps'), 129 'apps': MakeDictForPlatform('apps'),
88 'extensions': MakeDictForPlatform('extensions') 130 'extensions': MakeDictForPlatform('extensions'),
89 } 131 }
90 132
91 def Create(self): 133 def Create(self):
92 return APIListDataSource(self, self._object_store_creator) 134 return APIListDataSource(self, self._object_store_creator)
93 135
94 def __init__(self, factory, object_store_creator): 136 def __init__(self, factory, object_store_creator):
95 self._factory = factory 137 self._factory = factory
96 self._object_store = object_store_creator.Create(APIListDataSource) 138 self._object_store = object_store_creator.Create(APIListDataSource)
97 139
98 def _GetCachedAPIData(self): 140 def _GetCachedAPIData(self):
99 data = self._object_store.Get('api_data').Get() 141 data = self._object_store.Get('api_data').Get()
100 if data is None: 142 if data is None:
101 data = self._factory._GenerateAPIDict() 143 data = self._factory._GenerateAPIDict()
102 self._object_store.Set('api_data', data) 144 self._object_store.Set('api_data', data)
103 return data 145 return data
104 146
105 def get(self, key): 147 def get(self, key):
106 return self._GetCachedAPIData().get(key) 148 return self._GetCachedAPIData().get(key)
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_list_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698