Chromium Code Reviews| 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 os | 5 import os |
| 6 import posixpath | 6 import posixpath |
| 7 | 7 |
| 8 from compiled_file_system import SingleFile, Unicode | 8 from compiled_file_system import SingleFile, Unicode |
| 9 from extensions_paths import API | 9 from extensions_paths import API, CORE_API |
| 10 from file_system import FileNotFoundError | 10 from file_system import FileNotFoundError |
| 11 from future import Gettable, Future | 11 from future import Gettable, Future |
| 12 from schema_util import ProcessSchema | 12 from schema_util import ProcessSchema |
| 13 from third_party.json_schema_compiler.model import Namespace, UnixName | 13 from third_party.json_schema_compiler.model import Namespace, UnixName |
| 14 | 14 |
| 15 | 15 |
| 16 @SingleFile | 16 @SingleFile |
| 17 @Unicode | 17 @Unicode |
| 18 def _CreateAPIModel(path, data): | 18 def _CreateAPIModel(path, data): |
| 19 schema = ProcessSchema(path, data)[0] | 19 schema = ProcessSchema(path, data)[0] |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 38 api_features = self._features_bundle.GetAPIFeatures().Get() | 38 api_features = self._features_bundle.GetAPIFeatures().Get() |
| 39 return [name for name, feature in api_features.iteritems() | 39 return [name for name, feature in api_features.iteritems() |
| 40 if ('.' not in name or | 40 if ('.' not in name or |
| 41 name.rsplit('.', 1)[0] not in api_features or | 41 name.rsplit('.', 1)[0] not in api_features or |
| 42 feature.get('noparent'))] | 42 feature.get('noparent'))] |
| 43 | 43 |
| 44 def GetModel(self, api_name): | 44 def GetModel(self, api_name): |
| 45 # Callers sometimes specify a filename which includes .json or .idl - if | 45 # Callers sometimes specify a filename which includes .json or .idl - if |
| 46 # so, believe them. They may even include the 'api/' prefix. | 46 # so, believe them. They may even include the 'api/' prefix. |
| 47 if os.path.splitext(api_name)[1] in ('.json', '.idl'): | 47 if os.path.splitext(api_name)[1] in ('.json', '.idl'): |
| 48 if not api_name.startswith(API): | 48 if not api_name.startswith(API): |
|
not at google - send to devlin
2014/03/06 22:16:21
I guess this isn't a problem yet? I think it may b
Ken Rockot(use gerrit already)
2014/03/06 23:55:16
Done.
| |
| 49 api_name = posixpath.join(API, api_name) | 49 api_name = posixpath.join(API, api_name) |
| 50 return self._model_cache.GetFromFile(api_name) | 50 return self._model_cache.GetFromFile(api_name) |
| 51 | 51 |
| 52 assert not api_name.startswith(API) | 52 assert not api_name.startswith(API) |
| 53 | 53 |
| 54 # API names are given as declarativeContent and app.window but file names | 54 # API names are given as declarativeContent and app.window but file names |
| 55 # will be declarative_content and app_window. | 55 # will be declarative_content and app_window. |
| 56 file_name = UnixName(api_name).replace('.', '_') | 56 file_name = UnixName(api_name).replace('.', '_') |
| 57 # Devtools APIs are in API/devtools/ not API/, and have their | 57 # Devtools APIs are in API/devtools/ not API/, and have their |
| 58 # "devtools" names removed from the file names. | 58 # "devtools" names removed from the file names. |
| 59 basename = posixpath.basename(file_name) | 59 basename = posixpath.basename(file_name) |
| 60 if 'devtools_' in basename: | 60 if 'devtools_' in basename: |
| 61 file_name = posixpath.join( | 61 file_name = posixpath.join( |
| 62 'devtools', file_name.replace(basename, | 62 'devtools', file_name.replace(basename, |
| 63 basename.replace('devtools_' , ''))) | 63 basename.replace('devtools_' , ''))) |
| 64 | 64 |
| 65 futures = [self._model_cache.GetFromFile( | 65 futures = [self._model_cache.GetFromFile( |
| 66 posixpath.join(API, '%s.%s' % (file_name, ext))) | 66 posixpath.join(api_path, '%s.%s' % (file_name, ext))) |
| 67 for ext in ('json', 'idl')] | 67 for ext in ('json', 'idl') |
| 68 for api_path in (API, CORE_API)] | |
| 68 def resolve(): | 69 def resolve(): |
| 69 for future in futures: | 70 for future in futures: |
| 70 try: | 71 try: |
| 71 return future.Get() | 72 return future.Get() |
| 72 except FileNotFoundError: pass | 73 except FileNotFoundError: pass |
| 73 # Propagate the first FileNotFoundError if neither were found. | 74 # Propagate the first FileNotFoundError if no files were found. |
| 74 futures[0].Get() | 75 futures[0].Get() |
| 75 return Future(delegate=Gettable(resolve)) | 76 return Future(delegate=Gettable(resolve)) |
| 76 | 77 |
| 77 def IterModels(self): | 78 def IterModels(self): |
| 78 future_models = [(name, self.GetModel(name)) for name in self.GetNames()] | 79 future_models = [(name, self.GetModel(name)) for name in self.GetNames()] |
| 79 for name, future_model in future_models: | 80 for name, future_model in future_models: |
| 80 try: | 81 try: |
| 81 model = future_model.Get() | 82 model = future_model.Get() |
| 82 except FileNotFoundError: | 83 except FileNotFoundError: |
| 83 continue | 84 continue |
| 84 if model: | 85 if model: |
| 85 yield name, model | 86 yield name, model |
| OLD | NEW |