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 logging | 6 import logging |
7 import re | 7 import re |
8 | 8 |
| 9 import file_system_cache as fs_cache |
9 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater | 10 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater |
10 import third_party.json_schema_compiler.model as model | 11 import third_party.json_schema_compiler.model as model |
11 import url_constants | 12 import url_constants |
12 | 13 |
13 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' | 14 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' |
14 | 15 |
15 class SamplesDataSource(object): | 16 class SamplesDataSource(object): |
16 """Constructs a list of samples and their respective files and api calls. | 17 """Constructs a list of samples and their respective files and api calls. |
17 """ | 18 """ |
18 | 19 |
19 class Factory(object): | 20 class Factory(object): |
20 """A factory to create SamplesDataSource instances bound to individual | 21 """A factory to create SamplesDataSource instances bound to individual |
21 Requests. | 22 Requests. |
22 """ | 23 """ |
23 def __init__(self, | 24 def __init__(self, |
24 branch, | 25 branch, |
25 file_system, | 26 file_system, |
26 github_file_system, | 27 github_file_system, |
27 cache_builder, | 28 cache_builder, |
28 github_cache_builder, | 29 github_cache_builder, |
29 samples_path): | 30 samples_path): |
30 self._file_system = file_system | 31 self._file_system = file_system |
31 self._github_file_system = github_file_system | 32 self._github_file_system = github_file_system |
32 self._static_path = ((('/' + branch) if branch != 'local' else '') + | 33 self._static_path = ((('/' + branch) if branch != 'local' else '') + |
33 '/static') | 34 '/static') |
34 self._extensions_cache = cache_builder.build(self._MakeSamplesList) | 35 self._extensions_cache = cache_builder.build(self._MakeSamplesList, |
| 36 fs_cache.EXTENSIONS) |
35 self._apps_cache = github_cache_builder.build( | 37 self._apps_cache = github_cache_builder.build( |
36 lambda x: self._MakeSamplesList(x, is_apps=True)) | 38 lambda x: self._MakeSamplesList(x, is_apps=True), |
| 39 fs_cache.APPS) |
37 self._samples_path = samples_path | 40 self._samples_path = samples_path |
38 | 41 |
39 def Create(self, request): | 42 def Create(self, request): |
40 """Returns a new SamplesDataSource bound to |request|. | 43 """Returns a new SamplesDataSource bound to |request|. |
41 """ | 44 """ |
42 return SamplesDataSource(self._extensions_cache, | 45 return SamplesDataSource(self._extensions_cache, |
43 self._apps_cache, | 46 self._apps_cache, |
44 self._samples_path, | 47 self._samples_path, |
45 request) | 48 request) |
46 | 49 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return return_list | 203 return return_list |
201 | 204 |
202 def __getitem__(self, key): | 205 def __getitem__(self, key): |
203 return self.get(key) | 206 return self.get(key) |
204 | 207 |
205 def get(self, key): | 208 def get(self, key): |
206 return { | 209 return { |
207 'apps': lambda: self._CreateSamplesDict('apps'), | 210 'apps': lambda: self._CreateSamplesDict('apps'), |
208 'extensions': lambda: self._CreateSamplesDict('extensions') | 211 'extensions': lambda: self._CreateSamplesDict('extensions') |
209 }.get(key, lambda: {})() | 212 }.get(key, lambda: {})() |
OLD | NEW |