| 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 hashlib | 5 import hashlib |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 from compiled_file_system import CompiledFileSystem | 10 from compiled_file_system import CompiledFileSystem |
| 11 from file_system import FileNotFoundError | 11 from file_system import FileNotFoundError |
| 12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater | 12 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater |
| 13 import third_party.json_schema_compiler.model as model | 13 import third_party.json_schema_compiler.model as model |
| 14 import url_constants | 14 import url_constants |
| 15 | 15 |
| 16 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' | 16 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' |
| 17 | 17 |
| 18 # Increment this if the data model changes for SamplesDataSource. | |
| 19 _VERSION = 4 | |
| 20 | |
| 21 class SamplesDataSource(object): | 18 class SamplesDataSource(object): |
| 22 """Constructs a list of samples and their respective files and api calls. | 19 """Constructs a list of samples and their respective files and api calls. |
| 23 """ | 20 """ |
| 24 class Factory(object): | 21 class Factory(object): |
| 25 """A factory to create SamplesDataSource instances bound to individual | 22 """A factory to create SamplesDataSource instances bound to individual |
| 26 Requests. | 23 Requests. |
| 27 """ | 24 """ |
| 28 def __init__(self, | 25 def __init__(self, |
| 29 channel, | 26 channel, |
| 30 extensions_file_system, | 27 extensions_file_system, |
| 31 apps_file_system, | 28 apps_file_system, |
| 32 ref_resolver_factory, | 29 ref_resolver_factory, |
| 33 object_store_creator_factory, | 30 object_store_creator_factory, |
| 34 extension_samples_path): | 31 extension_samples_path): |
| 35 self._svn_file_system = extensions_file_system | 32 self._svn_file_system = extensions_file_system |
| 36 self._github_file_system = apps_file_system | 33 self._github_file_system = apps_file_system |
| 37 self._static_path = '/%s/static' % channel | 34 self._static_path = '/%s/static' % channel |
| 38 self._ref_resolver = ref_resolver_factory.Create() | 35 self._ref_resolver = ref_resolver_factory.Create() |
| 39 self._extension_samples_path = extension_samples_path | 36 self._extension_samples_path = extension_samples_path |
| 40 def create_compiled_fs(fs, fn, category): | 37 def create_compiled_fs(fs, fn, category): |
| 41 return CompiledFileSystem.Factory( | 38 return CompiledFileSystem.Factory( |
| 42 fs, | 39 fs, |
| 43 object_store_creator_factory).Create(fn, | 40 object_store_creator_factory).Create(fn, |
| 44 SamplesDataSource, | 41 SamplesDataSource, |
| 45 category=category, | 42 category=category) |
| 46 version=_VERSION) | |
| 47 self._extensions_cache = create_compiled_fs(extensions_file_system, | 43 self._extensions_cache = create_compiled_fs(extensions_file_system, |
| 48 self._MakeSamplesList, | 44 self._MakeSamplesList, |
| 49 'extensions') | 45 'extensions') |
| 50 self._apps_cache = create_compiled_fs(apps_file_system, | 46 self._apps_cache = create_compiled_fs(apps_file_system, |
| 51 lambda *args: self._MakeSamplesList( | 47 lambda *args: self._MakeSamplesList( |
| 52 *args, is_apps=True), | 48 *args, is_apps=True), |
| 53 'apps') | 49 'apps') |
| 54 | 50 |
| 55 def Create(self, request): | 51 def Create(self, request): |
| 56 """Returns a new SamplesDataSource bound to |request|. | 52 """Returns a new SamplesDataSource bound to |request|. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 return_list.append(sample_data) | 249 return_list.append(sample_data) |
| 254 else: | 250 else: |
| 255 return_list.append(dict_) | 251 return_list.append(dict_) |
| 256 return return_list | 252 return return_list |
| 257 | 253 |
| 258 def get(self, key): | 254 def get(self, key): |
| 259 return { | 255 return { |
| 260 'apps': lambda: self._CreateSamplesDict('apps'), | 256 'apps': lambda: self._CreateSamplesDict('apps'), |
| 261 'extensions': lambda: self._CreateSamplesDict('extensions') | 257 'extensions': lambda: self._CreateSamplesDict('extensions') |
| 262 }.get(key, lambda: {})() | 258 }.get(key, lambda: {})() |
| OLD | NEW |