OLD | NEW |
---|---|
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 FilterAPIs(): |
72 return (api for api in api_features.itervalues() | 79 return (api for api |
73 if platform in api['platforms']) | 80 in self._features_bundle.GetAPIFeatures().Get().itervalues() |
81 if api['name'] in self._api_models.GetNames()) | |
82 | |
83 def GetChannelInfo(api_name): | |
84 return self._availability_finder.GetApiAvailability(api_name) | |
85 | |
86 def GetApiDescription(api_name): | |
87 try: | |
88 model = self._api_models.GetModel(api_name).Get() | |
89 return model.description if model else '' | |
90 except FileNotFoundError: | |
91 return '' | |
74 | 92 |
75 def MakeDictForPlatform(platform): | 93 def MakeDictForPlatform(platform): |
76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } | 94 platform_dict = { |
77 for api in FilterAPIs(platform): | 95 'chrome': {'stable': [], 'beta': [], 'dev': [], 'trunk': []} |
78 if api['name'] in documented_apis[platform]: | 96 } |
79 category = _GetAPICategory(api, documented_apis[platform]) | 97 private_apis = [] |
80 platform_dict[category].append(api) | 98 experimental_apis = [] |
81 for category, apis in platform_dict.iteritems(): | 99 all_apis = [] |
82 platform_dict[category] = sorted(apis, key=itemgetter('name')) | 100 |
83 utils.MarkLast(platform_dict[category]) | 101 for api in FilterAPIs(): |
102 api_name = api['name'] | |
103 category = _GetAPICategory(api_name, documented_apis[platform]) | |
104 api['description'] = GetApiDescription(api_name) | |
not at google - send to devlin
2013/11/11 15:58:04
This and below is modifying the live data returned
hukun
2013/11/13 15:36:44
Got it. If you do not mind, I fix it in next CL.
not at google - send to devlin
2013/11/13 15:49:56
Please fix it now, it's a pretty small change. It'
hukun
2013/11/13 17:41:29
Done. Fix it by using api_models.
| |
105 if category == 'chrome': | |
106 channel_info = GetChannelInfo(api_name) | |
107 channel = channel_info.channel | |
108 if channel == 'stable': | |
109 api['version'] = channel_info.version | |
110 platform_dict[category][channel].append(api) | |
111 all_apis.append(api) | |
112 elif category == 'experimental': | |
113 experimental_apis.append(api) | |
114 all_apis.append(api) | |
115 elif category == 'private': | |
116 private_apis.append(api) | |
117 | |
118 for channel, apis_by_channel in platform_dict['chrome'].iteritems(): | |
119 apis_by_channel = sorted(apis_by_channel, key=itemgetter('name')) | |
120 utils.MarkLast(apis_by_channel) | |
121 platform_dict['chrome'][channel] = apis_by_channel | |
122 | |
123 for key, apis in (('all', all_apis), | |
124 ('private', private_apis), | |
125 ('experimental', experimental_apis)): | |
126 apis = sorted(apis, key=itemgetter('name')) | |
127 utils.MarkLast(apis) | |
128 platform_dict[key] = apis | |
84 return platform_dict | 129 return platform_dict |
85 | |
86 return { | 130 return { |
87 'apps': MakeDictForPlatform('apps'), | 131 'apps': MakeDictForPlatform('apps'), |
88 'extensions': MakeDictForPlatform('extensions') | 132 'extensions': MakeDictForPlatform('extensions'), |
89 } | 133 } |
90 | 134 |
91 def Create(self): | 135 def Create(self): |
92 return APIListDataSource(self, self._object_store_creator) | 136 return APIListDataSource(self, self._object_store_creator) |
93 | 137 |
94 def __init__(self, factory, object_store_creator): | 138 def __init__(self, factory, object_store_creator): |
95 self._factory = factory | 139 self._factory = factory |
96 self._object_store = object_store_creator.Create(APIListDataSource) | 140 self._object_store = object_store_creator.Create(APIListDataSource) |
97 | 141 |
98 def _GetCachedAPIData(self): | 142 def _GetCachedAPIData(self): |
99 data = self._object_store.Get('api_data').Get() | 143 data = self._object_store.Get('api_data').Get() |
100 if data is None: | 144 if data is None: |
101 data = self._factory._GenerateAPIDict() | 145 data = self._factory._GenerateAPIDict() |
102 self._object_store.Set('api_data', data) | 146 self._object_store.Set('api_data', data) |
103 return data | 147 return data |
104 | 148 |
105 def get(self, key): | 149 def get(self, key): |
106 return self._GetCachedAPIData().get(key) | 150 return self._GetCachedAPIData().get(key) |
OLD | NEW |