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 | 8 |
8 from third_party.json_schema_compiler.json_parse import Parse | 9 from svn_constants import PUBLIC_TEMPLATE_PATH |
9 import third_party.json_schema_compiler.model as model | |
10 import docs_server_utils as utils | 10 import docs_server_utils as utils |
11 | 11 |
12 def _GetAPICategory(api, documented_apis): | 12 def _GetAPICategory(api, documented_apis): |
13 name = api['name'] | 13 name = api['name'] |
14 if (name.endswith('Private') or | 14 if (name.endswith('Private') or |
15 name not in documented_apis): | 15 name not in documented_apis): |
16 return 'private' | 16 return 'private' |
17 if name.startswith('experimental.'): | 17 if name.startswith('experimental.'): |
18 return 'experimental' | 18 return 'experimental' |
19 return 'chrome' | 19 return 'chrome' |
(...skipping 11 matching lines...) Expand all Loading... |
31 - It has an "extension_types" property in _api_features with either/both | 31 - It has an "extension_types" property in _api_features with either/both |
32 "extension"/"platform_app" values present. | 32 "extension"/"platform_app" values present. |
33 - It has a dependency in _{api,manifest,permission}_features with an | 33 - It has a dependency in _{api,manifest,permission}_features with an |
34 "extension_types" property where either/both "extension"/"platform_app" | 34 "extension_types" property where either/both "extension"/"platform_app" |
35 values are present. | 35 values are present. |
36 """ | 36 """ |
37 class Factory(object): | 37 class Factory(object): |
38 def __init__(self, | 38 def __init__(self, |
39 compiled_fs_factory, | 39 compiled_fs_factory, |
40 file_system, | 40 file_system, |
41 public_template_path, | |
42 features_bundle, | 41 features_bundle, |
43 object_store_creator): | 42 object_store_creator): |
44 self._file_system = file_system | 43 self._file_system = file_system |
45 def NormalizePath(string): | |
46 return string if string.endswith('/') else (string + '/') | |
47 self._public_template_path = NormalizePath(public_template_path) | |
48 self._cache = compiled_fs_factory.Create(file_system, | 44 self._cache = compiled_fs_factory.Create(file_system, |
49 self._CollectDocumentedAPIs, | 45 self._CollectDocumentedAPIs, |
50 APIListDataSource) | 46 APIListDataSource) |
51 self._features_bundle = features_bundle | 47 self._features_bundle = features_bundle |
52 self._object_store_creator = object_store_creator | 48 self._object_store_creator = object_store_creator |
53 | 49 |
54 def _CollectDocumentedAPIs(self, base_dir, files): | 50 def _CollectDocumentedAPIs(self, base_dir, files): |
55 def GetDocumentedAPIsForPlatform(names, platform): | 51 def GetDocumentedAPIsForPlatform(names, platform): |
56 public_templates = [] | 52 public_templates = [] |
57 for root, _, files in self._file_system.Walk( | 53 for root, _, files in self._file_system.Walk(posixpath.join( |
58 self._public_template_path + platform): | 54 PUBLIC_TEMPLATE_PATH, platform)): |
59 public_templates.extend( | 55 public_templates.extend( |
60 ('%s/%s' % (root, name)).lstrip('/') for name in files) | 56 ('%s/%s' % (root, name)).lstrip('/') for name in files) |
61 template_names = set(os.path.splitext(name)[0] | 57 template_names = set(os.path.splitext(name)[0] |
62 for name in public_templates) | 58 for name in public_templates) |
63 return [name.replace('_', '.') for name in template_names] | 59 return [name.replace('_', '.') for name in template_names] |
64 api_names = set(utils.SanitizeAPIName(name) for name in files) | 60 api_names = set(utils.SanitizeAPIName(name) for name in files) |
65 return { | 61 return { |
66 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), | 62 'apps': GetDocumentedAPIsForPlatform(api_names, 'apps'), |
67 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') | 63 'extensions': GetDocumentedAPIsForPlatform(api_names, 'extensions') |
68 } | 64 } |
69 | 65 |
70 def _GenerateAPIDict(self): | 66 def _GenerateAPIDict(self): |
71 documented_apis = self._cache.GetFromFileListing( | 67 documented_apis = self._cache.GetFromFileListing( |
72 self._public_template_path).Get() | 68 PUBLIC_TEMPLATE_PATH).Get() |
73 api_features = self._features_bundle.GetAPIFeatures() | 69 api_features = self._features_bundle.GetAPIFeatures() |
74 | 70 |
75 def FilterAPIs(platform): | 71 def FilterAPIs(platform): |
76 return (api for api in api_features.itervalues() | 72 return (api for api in api_features.itervalues() |
77 if platform in api['platforms']) | 73 if platform in api['platforms']) |
78 | 74 |
79 def MakeDictForPlatform(platform): | 75 def MakeDictForPlatform(platform): |
80 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } | 76 platform_dict = { 'chrome': [], 'experimental': [], 'private': [] } |
81 for api in FilterAPIs(platform): | 77 for api in FilterAPIs(platform): |
82 category = _GetAPICategory(api, documented_apis[platform]) | 78 category = _GetAPICategory(api, documented_apis[platform]) |
(...skipping 17 matching lines...) Expand all Loading... |
100 | 96 |
101 def _GetCachedAPIData(self): | 97 def _GetCachedAPIData(self): |
102 data = self._object_store.Get('api_data').Get() | 98 data = self._object_store.Get('api_data').Get() |
103 if data is None: | 99 if data is None: |
104 data = self._factory._GenerateAPIDict() | 100 data = self._factory._GenerateAPIDict() |
105 self._object_store.Set('api_data', data) | 101 self._object_store.Set('api_data', data) |
106 return data | 102 return data |
107 | 103 |
108 def get(self, key): | 104 def get(self, key): |
109 return self._GetCachedAPIData().get(key) | 105 return self._GetCachedAPIData().get(key) |
OLD | NEW |