| 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 from api_data_source import APIDataSource | 5 from api_data_source import APIDataSource |
| 6 from api_list_data_source import APIListDataSource | 6 from api_list_data_source import APIListDataSource |
| 7 from api_models import APIModels | 7 from api_models import APIModels |
| 8 from availability_finder import AvailabilityFinder | 8 from availability_finder import AvailabilityFinder |
| 9 from compiled_file_system import CompiledFileSystem | 9 from compiled_file_system import CompiledFileSystem |
| 10 from content_providers import ContentProviders | 10 from content_providers import ContentProviders |
| 11 from empty_dir_file_system import EmptyDirFileSystem | 11 from empty_dir_file_system import EmptyDirFileSystem |
| 12 from environment import IsDevServer | 12 from environment import IsDevServer |
| 13 from features_bundle import FeaturesBundle | 13 from features_bundle import FeaturesBundle |
| 14 from github_file_system_provider import GithubFileSystemProvider | 14 from github_file_system_provider import GithubFileSystemProvider |
| 15 from host_file_system_provider import HostFileSystemProvider | 15 from host_file_system_provider import HostFileSystemProvider |
| 16 from host_file_system_iterator import HostFileSystemIterator | 16 from host_file_system_iterator import HostFileSystemIterator |
| 17 from intro_data_source import IntroDataSource | 17 from intro_data_source import IntroDataSource |
| 18 from object_store_creator import ObjectStoreCreator | 18 from object_store_creator import ObjectStoreCreator |
| 19 from path_canonicalizer import PathCanonicalizer | 19 from path_canonicalizer import PathCanonicalizer |
| 20 from reference_resolver import ReferenceResolver | 20 from reference_resolver import ReferenceResolver |
| 21 from samples_data_source import SamplesDataSource | 21 from samples_data_source import SamplesDataSource |
| 22 import svn_constants | |
| 23 from template_renderer import TemplateRenderer | 22 from template_renderer import TemplateRenderer |
| 24 from test_branch_utility import TestBranchUtility | 23 from test_branch_utility import TestBranchUtility |
| 25 from test_object_store import TestObjectStore | 24 from test_object_store import TestObjectStore |
| 26 | 25 |
| 26 |
| 27 class ServerInstance(object): | 27 class ServerInstance(object): |
| 28 | 28 |
| 29 def __init__(self, | 29 def __init__(self, |
| 30 object_store_creator, | 30 object_store_creator, |
| 31 compiled_fs_factory, | 31 compiled_fs_factory, |
| 32 branch_utility, | 32 branch_utility, |
| 33 host_file_system_provider, | 33 host_file_system_provider, |
| 34 github_file_system_provider, | 34 github_file_system_provider, |
| 35 base_path='/'): | 35 base_path='/'): |
| 36 ''' | 36 ''' |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 self.api_list_data_source_factory = APIListDataSource.Factory( | 88 self.api_list_data_source_factory = APIListDataSource.Factory( |
| 89 self.compiled_fs_factory, | 89 self.compiled_fs_factory, |
| 90 host_fs_at_trunk, | 90 host_fs_at_trunk, |
| 91 self.features_bundle, | 91 self.features_bundle, |
| 92 self.object_store_creator) | 92 self.object_store_creator) |
| 93 | 93 |
| 94 self.api_data_source_factory = APIDataSource.Factory( | 94 self.api_data_source_factory = APIDataSource.Factory( |
| 95 self.compiled_fs_factory, | 95 self.compiled_fs_factory, |
| 96 host_fs_at_trunk, | 96 host_fs_at_trunk, |
| 97 svn_constants.API_PATH, | |
| 98 self.availability_finder, | 97 self.availability_finder, |
| 99 branch_utility) | 98 branch_utility) |
| 100 | 99 |
| 101 self.ref_resolver_factory = ReferenceResolver.Factory( | 100 self.ref_resolver_factory = ReferenceResolver.Factory( |
| 102 self.api_data_source_factory, | 101 self.api_data_source_factory, |
| 103 self.api_models, | 102 self.api_models, |
| 104 object_store_creator) | 103 object_store_creator) |
| 105 | 104 |
| 106 self.api_data_source_factory.SetReferenceResolverFactory( | 105 self.api_data_source_factory.SetReferenceResolverFactory( |
| 107 self.ref_resolver_factory) | 106 self.ref_resolver_factory) |
| 108 | 107 |
| 109 # Note: samples are super slow in the dev server because it doesn't support | 108 # Note: samples are super slow in the dev server because it doesn't support |
| 110 # async fetch, so disable them. | 109 # async fetch, so disable them. |
| 111 if IsDevServer(): | 110 if IsDevServer(): |
| 112 extension_samples_fs = EmptyDirFileSystem() | 111 extension_samples_fs = EmptyDirFileSystem() |
| 113 app_samples_fs = EmptyDirFileSystem() | 112 app_samples_fs = EmptyDirFileSystem() |
| 114 else: | 113 else: |
| 115 extension_samples_fs = host_fs_at_trunk | 114 extension_samples_fs = host_fs_at_trunk |
| 116 app_samples_fs = github_file_system_provider.Create( | 115 app_samples_fs = github_file_system_provider.Create( |
| 117 'GoogleChrome', 'chrome-app-samples') | 116 'GoogleChrome', 'chrome-app-samples') |
| 118 self.samples_data_source_factory = SamplesDataSource.Factory( | 117 self.samples_data_source_factory = SamplesDataSource.Factory( |
| 119 extension_samples_fs, | 118 extension_samples_fs, |
| 120 app_samples_fs, | 119 app_samples_fs, |
| 121 CompiledFileSystem.Factory(object_store_creator), | 120 CompiledFileSystem.Factory(object_store_creator), |
| 122 self.ref_resolver_factory, | 121 self.ref_resolver_factory, |
| 123 svn_constants.EXAMPLES_PATH, | |
| 124 base_path) | 122 base_path) |
| 125 | 123 |
| 126 self.api_data_source_factory.SetSamplesDataSourceFactory( | 124 self.api_data_source_factory.SetSamplesDataSourceFactory( |
| 127 self.samples_data_source_factory) | 125 self.samples_data_source_factory) |
| 128 | 126 |
| 129 self.intro_data_source_factory = IntroDataSource.Factory( | 127 self.intro_data_source_factory = IntroDataSource.Factory( |
| 130 self.compiled_fs_factory, | 128 self.compiled_fs_factory, |
| 131 host_fs_at_trunk, | 129 host_fs_at_trunk, |
| 132 self.ref_resolver_factory, | 130 self.ref_resolver_factory) |
| 133 [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) | |
| 134 | 131 |
| 135 self.path_canonicalizer = PathCanonicalizer( | 132 self.path_canonicalizer = PathCanonicalizer( |
| 136 self.compiled_fs_factory, | 133 self.compiled_fs_factory, |
| 137 host_fs_at_trunk) | 134 host_fs_at_trunk) |
| 138 | 135 |
| 139 self.content_providers = ContentProviders( | 136 self.content_providers = ContentProviders( |
| 140 self.compiled_fs_factory, | 137 self.compiled_fs_factory, |
| 141 host_fs_at_trunk, | 138 host_fs_at_trunk, |
| 142 self.github_file_system_provider) | 139 self.github_file_system_provider) |
| 143 | 140 |
| 144 # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, | 141 # TODO(kalman): Move all the remaining DataSources into DataSourceRegistry, |
| 145 # then factor out the DataSource creation into a factory method, so that | 142 # then factor out the DataSource creation into a factory method, so that |
| 146 # the entire ServerInstance doesn't need to be passed in here. | 143 # the entire ServerInstance doesn't need to be passed in here. |
| 147 self.template_renderer = TemplateRenderer(self) | 144 self.template_renderer = TemplateRenderer(self) |
| 148 | 145 |
| 149 self.strings_json_path = svn_constants.STRINGS_JSON_PATH | |
| 150 self.manifest_json_path = svn_constants.MANIFEST_JSON_PATH | |
| 151 self.manifest_features_path = svn_constants.MANIFEST_FEATURES_PATH | |
| 152 | |
| 153 @staticmethod | 146 @staticmethod |
| 154 def ForTest(file_system, base_path='/'): | 147 def ForTest(file_system, base_path='/'): |
| 155 object_store_creator = ObjectStoreCreator.ForTest() | 148 object_store_creator = ObjectStoreCreator.ForTest() |
| 156 return ServerInstance(object_store_creator, | 149 return ServerInstance(object_store_creator, |
| 157 CompiledFileSystem.Factory(object_store_creator), | 150 CompiledFileSystem.Factory(object_store_creator), |
| 158 TestBranchUtility.CreateWithCannedData(), | 151 TestBranchUtility.CreateWithCannedData(), |
| 159 HostFileSystemProvider.ForTest(file_system, | 152 HostFileSystemProvider.ForTest(file_system, |
| 160 object_store_creator), | 153 object_store_creator), |
| 161 GithubFileSystemProvider.ForEmpty(), | 154 GithubFileSystemProvider.ForEmpty(), |
| 162 base_path=base_path) | 155 base_path=base_path) |
| 163 | 156 |
| 164 @staticmethod | 157 @staticmethod |
| 165 def ForLocal(): | 158 def ForLocal(): |
| 166 object_store_creator = ObjectStoreCreator(start_empty=False, | 159 object_store_creator = ObjectStoreCreator(start_empty=False, |
| 167 store_type=TestObjectStore) | 160 store_type=TestObjectStore) |
| 168 host_file_system_provider = HostFileSystemProvider.ForLocal( | 161 host_file_system_provider = HostFileSystemProvider.ForLocal( |
| 169 object_store_creator) | 162 object_store_creator) |
| 170 return ServerInstance( | 163 return ServerInstance( |
| 171 object_store_creator, | 164 object_store_creator, |
| 172 CompiledFileSystem.Factory(object_store_creator), | 165 CompiledFileSystem.Factory(object_store_creator), |
| 173 TestBranchUtility.CreateWithCannedData(), | 166 TestBranchUtility.CreateWithCannedData(), |
| 174 host_file_system_provider, | 167 host_file_system_provider, |
| 175 GithubFileSystemProvider.ForEmpty()) | 168 GithubFileSystemProvider.ForEmpty()) |
| OLD | NEW |