OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 collections import Mapping | 5 from collections import Mapping |
6 import posixpath | 6 import posixpath |
7 | 7 |
8 from api_schema_graph import APISchemaGraph | 8 from api_schema_graph import APISchemaGraph |
9 from branch_utility import BranchUtility | 9 from branch_utility import BranchUtility |
10 from extensions_paths import API, JSON_TEMPLATES | 10 from extensions_paths import API, CORE_API, JSON_TEMPLATES |
11 from third_party.json_schema_compiler.model import UnixName | 11 from third_party.json_schema_compiler.model import UnixName |
12 | 12 |
13 | 13 |
14 _EXTENSION_API = 'extension_api.json' | 14 _EXTENSION_API = 'extension_api.json' |
15 | 15 |
16 # The version where api_features.json is first available. | 16 # The version where api_features.json is first available. |
17 _API_FEATURES_MIN_VERSION = 28 | 17 _API_FEATURES_MIN_VERSION = 28 |
18 # The version where permission_ and manifest_features.json are available and | 18 # The version where permission_ and manifest_features.json are available and |
19 # presented in the current format. | 19 # presented in the current format. |
20 _ORIGINAL_FEATURES_MIN_VERSION = 20 | 20 _ORIGINAL_FEATURES_MIN_VERSION = 20 |
21 # API schemas are aggregated in extension_api.json up to this version. | 21 # API schemas are aggregated in extension_api.json up to this version. |
22 _EXTENSION_API_MAX_VERSION = 17 | 22 _EXTENSION_API_MAX_VERSION = 17 |
23 # The earliest version for which we have SVN data. | 23 # The earliest version for which we have SVN data. |
24 _SVN_MIN_VERSION = 5 | 24 _SVN_MIN_VERSION = 5 |
25 | 25 |
26 | 26 |
27 def _GetChannelFromFeatures(api_name, json_fs, filename): | 27 def _GetChannelFromFeatures(api_name, json_fs, filename): |
28 '''Finds API channel information from the features |filename| within the the | 28 '''Finds API channel information from the features |filename| within the the |
29 given |json_fs|. Returns None if channel information for the API cannot be | 29 given |json_fs|. Returns None if channel information for the API cannot be |
30 located. | 30 located. |
31 ''' | 31 ''' |
32 feature = json_fs.GetFromFile(API + filename).Get().get(api_name) | 32 feature = json_fs.GetFromFile(API + filename).Get().get(api_name) |
not at google - send to devlin
2014/03/06 22:16:21
bleh, let's update these functions to take the act
Ken Rockot(use gerrit already)
2014/03/06 23:55:16
Done.
| |
33 if feature is None: | 33 if feature is None: |
34 return None | 34 return None |
35 if isinstance(feature, Mapping): | 35 if isinstance(feature, Mapping): |
36 # The channel information exists as a solitary dict. | 36 # The channel information exists as a solitary dict. |
37 return feature.get('channel') | 37 return feature.get('channel') |
38 # The channel information dict is nested within a list for whitelisting | 38 # The channel information dict is nested within a list for whitelisting |
39 # purposes. Take the newest channel out of all of the entries. | 39 # purposes. Take the newest channel out of all of the entries. |
40 return BranchUtility.NewestChannel(entry.get('channel') for entry in feature) | 40 return BranchUtility.NewestChannel(entry.get('channel') for entry in feature) |
41 | 41 |
42 | 42 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 return self._branch_utility.GetStableChannelInfo(api_info['version']) | 88 return self._branch_utility.GetStableChannelInfo(api_info['version']) |
89 else: | 89 else: |
90 return self._branch_utility.GetChannelInfo(api_info['channel']) | 90 return self._branch_utility.GetChannelInfo(api_info['channel']) |
91 | 91 |
92 def _GetApiSchemaFilename(self, api_name, file_system, version): | 92 def _GetApiSchemaFilename(self, api_name, file_system, version): |
93 '''Gets the name of the file which may contain the schema for |api_name| in | 93 '''Gets the name of the file which may contain the schema for |api_name| in |
94 |file_system|, or None if the API is not found. Note that this may be the | 94 |file_system|, or None if the API is not found. Note that this may be the |
95 single _EXTENSION_API file which all APIs share in older versions of Chrome, | 95 single _EXTENSION_API file which all APIs share in older versions of Chrome, |
96 in which case it is unknown whether the API actually exists there. | 96 in which case it is unknown whether the API actually exists there. |
97 ''' | 97 ''' |
98 def under_api_path(path): | 98 def find_schema_under_path(api_name, path): |
99 return API + path | 99 # |file_system| will cache the results from the ReadSingle() call. |
100 if not file_system.Exists(path).Get(): | |
101 return None | |
102 filenames = file_system.ReadSingle(path).Get() | |
103 for ext in ('json', 'idl'): | |
104 filename = '%s.%s' % (api_name, ext) | |
105 if filename in filenames: | |
106 return path + filename | |
107 if _EXTENSION_API in filenames: | |
108 return path + _EXTENSION_API | |
109 # API schema data could not be found in any .json or .idl file. | |
110 return None | |
100 | 111 |
101 if version == 'trunk' or version > _ORIGINAL_FEATURES_MIN_VERSION: | 112 if version == 'trunk' or version > _ORIGINAL_FEATURES_MIN_VERSION: |
102 # API schema filenames switch format to unix_hacker_style. | 113 # API schema filenames switch format to unix_hacker_style. |
103 api_name = UnixName(api_name) | 114 api_name = UnixName(api_name) |
104 | 115 |
105 # |file_system| will cache the results from the ReadSingle() call. | 116 filename = find_schema_under_path(api_name, CORE_API) |
106 filenames = file_system.ReadSingle(API).Get() | 117 if filename is not None: |
107 | 118 return filename |
108 for ext in ('json', 'idl'): | 119 return find_schema_under_path(api_name, API) |
109 filename = '%s.%s' % (api_name, ext) | |
110 if filename in filenames: | |
111 return under_api_path(filename) | |
112 if _EXTENSION_API in filenames: | |
113 return under_api_path(_EXTENSION_API) | |
114 # API schema data could not be found in any .json or .idl file. | |
115 return None | |
116 | 120 |
117 def _GetApiSchema(self, api_name, file_system, version): | 121 def _GetApiSchema(self, api_name, file_system, version): |
118 '''Searches |file_system| for |api_name|'s API schema data, and processes | 122 '''Searches |file_system| for |api_name|'s API schema data, and processes |
119 and returns it if found. | 123 and returns it if found. |
120 ''' | 124 ''' |
121 api_filename = self._GetApiSchemaFilename(api_name, file_system, version) | 125 api_filename = self._GetApiSchemaFilename(api_name, file_system, version) |
122 if api_filename is None: | 126 if api_filename is None: |
123 # No file for the API could be found in the given |file_system|. | 127 # No file for the API could be found in the given |file_system|. |
124 return None | 128 return None |
125 | 129 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 | 284 |
281 # Continue looping until there are no longer differences between this | 285 # Continue looping until there are no longer differences between this |
282 # version and trunk. | 286 # version and trunk. |
283 return version_stat != trunk_stat | 287 return version_stat != trunk_stat |
284 | 288 |
285 self._file_system_iterator.Ascending(self.GetApiAvailability(api_name), | 289 self._file_system_iterator.Ascending(self.GetApiAvailability(api_name), |
286 update_availability_graph) | 290 update_availability_graph) |
287 | 291 |
288 self._node_level_object_store.Set(api_name, availability_graph) | 292 self._node_level_object_store.Set(api_name, availability_graph) |
289 return availability_graph | 293 return availability_graph |
OLD | NEW |