| 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 logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 | 8 |
| 9 from compiled_file_system import SingleFile | 9 from compiled_file_system import SingleFile |
| 10 from extensions_paths import API | 10 from extensions_paths import API |
| 11 from file_system import FileNotFoundError | 11 from file_system import FileNotFoundError |
| 12 from future import Gettable, Future | 12 from future import Gettable, Future |
| 13 from schema_util import ProcessSchema | 13 from schema_util import ProcessSchema |
| 14 from third_party.json_schema_compiler.model import Namespace, UnixName | 14 from third_party.json_schema_compiler.model import Namespace, UnixName |
| 15 | 15 |
| 16 | 16 |
| 17 @SingleFile | 17 @SingleFile |
| 18 def _CreateAPIModel(path, data): | 18 def _CreateAPIModel(path, data): |
| 19 schema = ProcessSchema(path, data) | 19 schema = ProcessSchema(path, data) |
| 20 if os.path.splitext(path)[1] == '.json': | 20 if os.path.splitext(path)[1] == '.json': |
| 21 schema = schema[0] | 21 schema = schema[0] |
| 22 if not schema: return None |
| 22 return Namespace(schema, schema['namespace']) | 23 return Namespace(schema, schema['namespace']) |
| 23 | 24 |
| 24 | 25 |
| 25 class APIModels(object): | 26 class APIModels(object): |
| 26 '''Tracks APIs and their Models. | 27 '''Tracks APIs and their Models. |
| 27 ''' | 28 ''' |
| 28 | 29 |
| 29 def __init__(self, features_bundle, compiled_fs_factory, file_system): | 30 def __init__(self, features_bundle, compiled_fs_factory, file_system): |
| 30 self._features_bundle = features_bundle | 31 self._features_bundle = features_bundle |
| 31 self._model_cache = compiled_fs_factory.Create( | 32 self._model_cache = compiled_fs_factory.Create( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 futures = [self._model_cache.GetFromFile('%s/%s.%s' % (API, file_name, ext)) | 66 futures = [self._model_cache.GetFromFile('%s/%s.%s' % (API, file_name, ext)) |
| 66 for ext in ('json', 'idl')] | 67 for ext in ('json', 'idl')] |
| 67 def resolve(): | 68 def resolve(): |
| 68 for future in futures: | 69 for future in futures: |
| 69 try: | 70 try: |
| 70 return future.Get() | 71 return future.Get() |
| 71 except FileNotFoundError: pass | 72 except FileNotFoundError: pass |
| 72 # Propagate the first FileNotFoundError if neither were found. | 73 # Propagate the first FileNotFoundError if neither were found. |
| 73 futures[0].Get() | 74 futures[0].Get() |
| 74 return Future(delegate=Gettable(resolve)) | 75 return Future(delegate=Gettable(resolve)) |
| 76 |
| 77 def IterModels(self): |
| 78 return dict((name, self.GetModel(name)) |
| 79 for name in self.GetNames()).iteritems() |
| OLD | NEW |