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 import json | 5 import json |
6 import os | 6 import os |
7 | 7 |
8 from handlebar_dict_generator import HandlebarDictGenerator | 8 from handlebar_dict_generator import HandlebarDictGenerator |
9 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater | 9 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater |
10 import third_party.json_schema_compiler.model as model | 10 import third_party.json_schema_compiler.model as model |
11 import third_party.json_schema_compiler.idl_schema as idl_schema | 11 import third_party.json_schema_compiler.idl_schema as idl_schema |
12 import third_party.json_schema_compiler.idl_parser as idl_parser | 12 import third_party.json_schema_compiler.idl_parser as idl_parser |
13 | 13 |
14 class APIDataSource(object): | 14 class APIDataSource(object): |
15 """This class fetches and loads JSON APIs with the fetcher passed in with | 15 """This class fetches and loads JSON APIs from the FileSystem passed in with |
16 |cache_builder|, so the APIs can be plugged into templates. | 16 |cache_builder|, so the APIs can be plugged into templates. |
17 """ | 17 """ |
18 def __init__(self, cache_builder, base_path): | 18 def __init__(self, cache_builder, base_path): |
19 self._json_cache = cache_builder.build(self._LoadJsonAPI) | 19 self._json_cache = cache_builder.build(self._LoadJsonAPI) |
20 self._idl_cache = cache_builder.build(self._LoadIdlAPI) | 20 self._idl_cache = cache_builder.build(self._LoadIdlAPI) |
21 self._base_path = base_path | 21 self._base_path = base_path |
22 | 22 |
23 def _LoadJsonAPI(self, api): | 23 def _LoadJsonAPI(self, api): |
24 generator = HandlebarDictGenerator( | 24 generator = HandlebarDictGenerator( |
25 json.loads(json_comment_eater.Nom(api))[0]) | 25 json.loads(json_comment_eater.Nom(api))[0]) |
(...skipping 12 matching lines...) Expand all Loading... |
38 unix_name = model.UnixName(path) | 38 unix_name = model.UnixName(path) |
39 json_path = unix_name + '.json' | 39 json_path = unix_name + '.json' |
40 idl_path = unix_name + '.idl' | 40 idl_path = unix_name + '.idl' |
41 try: | 41 try: |
42 return self._json_cache.GetFromFile(self._base_path + '/' + json_path) | 42 return self._json_cache.GetFromFile(self._base_path + '/' + json_path) |
43 except Exception: | 43 except Exception: |
44 try: | 44 try: |
45 return self._idl_cache.GetFromFile(self._base_path + '/' + idl_path) | 45 return self._idl_cache.GetFromFile(self._base_path + '/' + idl_path) |
46 except Exception: | 46 except Exception: |
47 return None | 47 return None |
OLD | NEW |