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 import posixpath | 5 import posixpath |
6 | 6 |
7 from compiled_file_system import SingleFile, Unicode | 7 from compiled_file_system import SingleFile, Unicode |
8 from extensions_paths import API, CHROME_API | 8 from extensions_paths import API_PATHS |
9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
10 from future import Future | 10 from future import Future |
11 from schema_util import ProcessSchema | 11 from schema_util import ProcessSchema |
12 from third_party.json_schema_compiler.model import Namespace, UnixName | 12 from third_party.json_schema_compiler.model import Namespace, UnixName |
13 | 13 |
14 | 14 |
15 @SingleFile | 15 @SingleFile |
16 @Unicode | 16 @Unicode |
17 def _CreateAPIModel(path, data): | 17 def _CreateAPIModel(path, data): |
18 schema = ProcessSchema(path, data)[0] | 18 schema = ProcessSchema(path, data)[0] |
(...skipping 18 matching lines...) Expand all Loading... |
37 api_features = self._features_bundle.GetAPIFeatures().Get() | 37 api_features = self._features_bundle.GetAPIFeatures().Get() |
38 return [name for name, feature in api_features.iteritems() | 38 return [name for name, feature in api_features.iteritems() |
39 if ('.' not in name or | 39 if ('.' not in name or |
40 name.rsplit('.', 1)[0] not in api_features or | 40 name.rsplit('.', 1)[0] not in api_features or |
41 feature.get('noparent'))] | 41 feature.get('noparent'))] |
42 | 42 |
43 def GetModel(self, api_name): | 43 def GetModel(self, api_name): |
44 # By default |api_name| is assumed to be given without a path or extension, | 44 # By default |api_name| is assumed to be given without a path or extension, |
45 # so combinations of known paths and extension types will be searched. | 45 # so combinations of known paths and extension types will be searched. |
46 api_extensions = ('.json', '.idl') | 46 api_extensions = ('.json', '.idl') |
47 api_paths = (CHROME_API, API) | 47 api_paths = API_PATHS |
48 | 48 |
49 # Callers sometimes include a file extension and/or prefix path with the | 49 # Callers sometimes include a file extension and/or prefix path with the |
50 # |api_name| argument. We believe them and narrow the search space | 50 # |api_name| argument. We believe them and narrow the search space |
51 # accordingly. | 51 # accordingly. |
52 name, ext = posixpath.splitext(api_name) | 52 name, ext = posixpath.splitext(api_name) |
53 if ext in api_extensions: | 53 if ext in api_extensions: |
54 api_extensions = (ext,) | 54 api_extensions = (ext,) |
55 api_name = name | 55 api_name = name |
56 for api_path in api_paths: | 56 for api_path in api_paths: |
57 if api_name.startswith(api_path): | 57 if api_name.startswith(api_path): |
(...skipping 27 matching lines...) Expand all Loading... |
85 | 85 |
86 def IterModels(self): | 86 def IterModels(self): |
87 future_models = [(name, self.GetModel(name)) for name in self.GetNames()] | 87 future_models = [(name, self.GetModel(name)) for name in self.GetNames()] |
88 for name, future_model in future_models: | 88 for name, future_model in future_models: |
89 try: | 89 try: |
90 model = future_model.Get() | 90 model = future_model.Get() |
91 except FileNotFoundError: | 91 except FileNotFoundError: |
92 continue | 92 continue |
93 if model: | 93 if model: |
94 yield name, model | 94 yield name, model |
OLD | NEW |