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 svn_constants import PUBLIC_TEMPLATE_PATH | 9 from svn_constants import PUBLIC_TEMPLATE_PATH |
10 import docs_server_utils as utils | 10 import docs_server_utils as utils |
11 from file_system import FileNotFoundError | |
11 | 12 |
12 def _GetAPICategory(api, documented_apis): | 13 def _GetAPICategory(api, documented_apis): |
13 name = api['name'] | 14 name = api['name'] |
14 if (name.endswith('Private') or | 15 if (name.endswith('Private') or |
15 name not in documented_apis): | 16 name not in documented_apis): |
16 return 'private' | 17 return 'private' |
17 if name.startswith('experimental.'): | 18 if name.startswith('experimental.'): |
18 return 'experimental' | 19 return 'experimental' |
19 return 'chrome' | 20 return 'chrome' |
20 | 21 |
(...skipping 11 matching lines...) Expand all Loading... | |
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() | |
57 | |
58 def _GetApiFeatures(self): | |
59 return self._features_bundle.GetAPIFeatures() | |
49 | 60 |
50 def _CollectDocumentedAPIs(self, base_dir, files): | 61 def _CollectDocumentedAPIs(self, base_dir, files): |
51 def GetDocumentedAPIsForPlatform(names, platform): | 62 def GetDocumentedAPIsForPlatform(names, platform): |
52 public_templates = [] | 63 public_templates = [] |
53 for root, _, files in self._file_system.Walk(posixpath.join( | 64 for root, _, files in self._file_system.Walk(posixpath.join( |
54 PUBLIC_TEMPLATE_PATH, platform)): | 65 PUBLIC_TEMPLATE_PATH, platform)): |
55 public_templates.extend( | 66 public_templates.extend( |
56 ('%s/%s' % (root, name)).lstrip('/') for name in files) | 67 ('%s/%s' % (root, name)).lstrip('/') for name in files) |
57 template_names = set(os.path.splitext(name)[0] | 68 template_names = set(os.path.splitext(name)[0] |
58 for name in public_templates) | 69 for name in public_templates) |
59 return [name.replace('_', '.') for name in template_names] | 70 return [name.replace('_', '.') for name in template_names] |
60 api_names = set(utils.SanitizeAPIName(name) for name in files) | 71 api_names = set(utils.SanitizeAPIName(name) for name in files) |
61 return { | 72 return { |
62 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), | 73 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), |
63 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') | 74 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') |
64 } | 75 } |
65 | 76 |
66 def _GenerateAPIDict(self): | 77 def _GenerateAPIDict(self): |
67 documented_apis = self._cache.GetFromFileListing( | 78 documented_apis = self._cache.GetFromFileListing( |
68 PUBLIC_TEMPLATE_PATH).Get() | 79 PUBLIC_TEMPLATE_PATH).Get() |
69 api_features = self._features_bundle.GetAPIFeatures() | |
70 | 80 |
71 def FilterAPIs(platform): | 81 def FilterAPIs(platform): |
72 return (api for api in api_features.itervalues() | 82 return (api for api |
83 in self._features_bundle.GetAPIFeatures().itervalues() | |
73 if platform in api['platforms']) | 84 if platform in api['platforms']) |
74 | 85 |
86 def GetChannelInfo(api_name): | |
87 return self._availability_finder.GetApiAvailability(api_name) | |
88 | |
89 def GetApiDescription(api_name): | |
90 try: | |
91 model = self._api_models.GetModel(api_name).Get() | |
92 if model: | |
93 return model.description | |
94 else: | |
95 return '' | |
not at google - send to devlin
2013/11/07 23:52:18
you can also write this more concisely:
model = s
hukun
2013/11/08 06:23:39
I did filter the api by _api_models.GetName() befo
not at google - send to devlin
2013/11/10 01:39:57
Oh because they have [nodoc]. Right. That is a pro
| |
96 except FileNotFoundError: | |
97 return '' | |
98 | |
75 def MakeDictForPlatform(platform): | 99 def MakeDictForPlatform(platform): |
76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } | 100 platform_dict = { |
101 'chrome': {'stable': [],'beta': [], 'dev': [],'trunk': []} | |
not at google - send to devlin
2013/11/07 23:52:18
some of these commas need spaces after them
hukun
2013/11/08 06:23:39
Done
| |
102 } | |
103 private_apis = [] | |
104 experimental_apis = [] | |
105 all_apis = [] | |
106 | |
77 for api in FilterAPIs(platform): | 107 for api in FilterAPIs(platform): |
not at google - send to devlin
2013/11/10 01:39:57
See comment above. Just loop over self._api_models
| |
78 if api['name'] in documented_apis[platform]: | 108 category = _GetAPICategory(api, documented_apis[platform]) |
79 category = _GetAPICategory(api, documented_apis[platform]) | 109 api_name = api['name'] |
80 platform_dict[category].append(api) | 110 if api_name in self._api_models.GetNames(): |
81 for category, apis in platform_dict.iteritems(): | 111 api['description'] = GetApiDescription(api_name) |
82 platform_dict[category] = sorted(apis, key=itemgetter('name')) | 112 if category == 'chrome': |
83 utils.MarkLast(platform_dict[category]) | 113 channel_info = GetChannelInfo(api_name) |
114 channel = channel_info.channel | |
115 if channel == 'stable': | |
116 api['version'] = channel_info.version | |
117 platform_dict[category][channel].append(api) | |
118 all_apis.append(api) | |
119 elif category == 'experimental': | |
120 experimental_apis.append(api) | |
121 all_apis.append(api) | |
122 elif category == 'private': | |
123 private_apis.append(api) | |
124 | |
125 for channel, apis_by_channel in platform_dict['chrome'].iteritems(): | |
126 apis_by_channel = sorted(apis_by_channel, key=itemgetter('name')) | |
127 utils.MarkLast(apis_by_channel) | |
128 platform_dict['chrome'][channel] = apis_by_channel | |
129 | |
130 for key, apis in (('all', all_apis), | |
131 ('private', private_apis), | |
132 ('experimental', experimental_apis)): | |
133 apis = sorted(apis, key=itemgetter('name')) | |
134 utils.MarkLast(apis) | |
135 platform_dict[key] = apis | |
84 return platform_dict | 136 return platform_dict |
85 | |
86 return { | 137 return { |
87 'apps': MakeDictForPlatform('apps'), | 138 'apps': MakeDictForPlatform('apps'), |
88 'extensions': MakeDictForPlatform('extensions') | 139 'extensions': MakeDictForPlatform('extensions'), |
89 } | 140 } |
90 | 141 |
91 def Create(self): | 142 def Create(self): |
92 return APIListDataSource(self, self._object_store_creator) | 143 return APIListDataSource(self, self._object_store_creator) |
93 | 144 |
94 def __init__(self, factory, object_store_creator): | 145 def __init__(self, factory, object_store_creator): |
95 self._factory = factory | 146 self._factory = factory |
96 self._object_store = object_store_creator.Create(APIListDataSource) | 147 self._object_store = object_store_creator.Create(APIListDataSource) |
97 | 148 |
98 def _GetCachedAPIData(self): | 149 def _GetCachedAPIData(self): |
99 data = self._object_store.Get('api_data').Get() | 150 data = self._object_store.Get('api_data').Get() |
100 if data is None: | 151 if data is None: |
101 data = self._factory._GenerateAPIDict() | 152 data = self._factory._GenerateAPIDict() |
102 self._object_store.Set('api_data', data) | 153 self._object_store.Set('api_data', data) |
103 return data | 154 return data |
104 | 155 |
105 def get(self, key): | 156 def get(self, key): |
106 return self._GetCachedAPIData().get(key) | 157 return self._GetCachedAPIData().get(key) |
OLD | NEW |