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 fnmatch import fnmatch | 5 from fnmatch import fnmatch |
6 import mimetypes | 6 import mimetypes |
7 import traceback | 7 import traceback |
8 import os | 8 import os |
9 | 9 |
10 from api_data_source import APIDataSource | 10 from api_data_source import APIDataSource |
(...skipping 19 matching lines...) Expand all Loading... |
30 from sidenav_data_source import SidenavDataSource | 30 from sidenav_data_source import SidenavDataSource |
31 import svn_constants | 31 import svn_constants |
32 from template_data_source import TemplateDataSource | 32 from template_data_source import TemplateDataSource |
33 from test_branch_utility import TestBranchUtility | 33 from test_branch_utility import TestBranchUtility |
34 from test_object_store import TestObjectStore | 34 from test_object_store import TestObjectStore |
35 from third_party.json_schema_compiler.model import UnixName | 35 from third_party.json_schema_compiler.model import UnixName |
36 import url_constants | 36 import url_constants |
37 | 37 |
38 class ServerInstance(object): | 38 class ServerInstance(object): |
39 def __init__(self, | 39 def __init__(self, |
40 channel, | |
41 object_store_creator, | 40 object_store_creator, |
42 host_file_system, | 41 host_file_system, |
43 app_samples_file_system, | 42 app_samples_file_system, |
44 base_path, | 43 base_path, |
45 compiled_fs_factory, | 44 compiled_fs_factory, |
46 branch_utility, | 45 branch_utility, |
47 host_file_system_creator): | 46 host_file_system_creator): |
48 self.channel = channel | |
49 | |
50 self.object_store_creator = object_store_creator | 47 self.object_store_creator = object_store_creator |
51 | 48 |
52 self.host_file_system = host_file_system | 49 self.host_file_system = host_file_system |
53 | 50 |
54 self.app_samples_file_system = app_samples_file_system | 51 self.app_samples_file_system = app_samples_file_system |
55 | 52 |
56 self.compiled_host_fs_factory = compiled_fs_factory | 53 self.compiled_host_fs_factory = compiled_fs_factory |
57 | 54 |
58 self.host_file_system_creator = host_file_system_creator | 55 self.host_file_system_creator = host_file_system_creator |
59 | 56 |
(...skipping 21 matching lines...) Expand all Loading... |
81 self.api_data_source_factory.SetReferenceResolverFactory( | 78 self.api_data_source_factory.SetReferenceResolverFactory( |
82 self.ref_resolver_factory) | 79 self.ref_resolver_factory) |
83 | 80 |
84 # Note: samples are super slow in the dev server because it doesn't support | 81 # Note: samples are super slow in the dev server because it doesn't support |
85 # async fetch, so disable them. | 82 # async fetch, so disable them. |
86 if IsDevServer(): | 83 if IsDevServer(): |
87 extension_samples_fs = EmptyDirFileSystem() | 84 extension_samples_fs = EmptyDirFileSystem() |
88 else: | 85 else: |
89 extension_samples_fs = self.host_file_system | 86 extension_samples_fs = self.host_file_system |
90 self.samples_data_source_factory = SamplesDataSource.Factory( | 87 self.samples_data_source_factory = SamplesDataSource.Factory( |
91 channel, | |
92 extension_samples_fs, | 88 extension_samples_fs, |
93 CompiledFileSystem.Factory(extension_samples_fs, object_store_creator), | 89 CompiledFileSystem.Factory(extension_samples_fs, object_store_creator), |
94 self.app_samples_file_system, | 90 self.app_samples_file_system, |
95 CompiledFileSystem.Factory(self.app_samples_file_system, | 91 CompiledFileSystem.Factory(self.app_samples_file_system, |
96 object_store_creator), | 92 object_store_creator), |
97 self.ref_resolver_factory, | 93 self.ref_resolver_factory, |
98 svn_constants.EXAMPLES_PATH) | 94 svn_constants.EXAMPLES_PATH, |
| 95 base_path) |
99 | 96 |
100 self.api_data_source_factory.SetSamplesDataSourceFactory( | 97 self.api_data_source_factory.SetSamplesDataSourceFactory( |
101 self.samples_data_source_factory) | 98 self.samples_data_source_factory) |
102 | 99 |
103 self.intro_data_source_factory = IntroDataSource.Factory( | 100 self.intro_data_source_factory = IntroDataSource.Factory( |
104 self.compiled_host_fs_factory, | 101 self.compiled_host_fs_factory, |
105 self.ref_resolver_factory, | 102 self.ref_resolver_factory, |
106 [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) | 103 [svn_constants.INTRO_PATH, svn_constants.ARTICLE_PATH]) |
107 | 104 |
108 self.sidenav_data_source_factory = SidenavDataSource.Factory( | 105 self.sidenav_data_source_factory = SidenavDataSource.Factory( |
109 self.compiled_host_fs_factory, | 106 self.compiled_host_fs_factory, |
110 svn_constants.JSON_PATH, | 107 svn_constants.JSON_PATH) |
111 base_path) | |
112 | 108 |
113 self.template_data_source_factory = TemplateDataSource.Factory( | 109 self.template_data_source_factory = TemplateDataSource.Factory( |
114 channel, | |
115 self.api_data_source_factory, | 110 self.api_data_source_factory, |
116 self.api_list_data_source_factory, | 111 self.api_list_data_source_factory, |
117 self.intro_data_source_factory, | 112 self.intro_data_source_factory, |
118 self.samples_data_source_factory, | 113 self.samples_data_source_factory, |
119 self.sidenav_data_source_factory, | 114 self.sidenav_data_source_factory, |
120 self.compiled_host_fs_factory, | 115 self.compiled_host_fs_factory, |
121 self.ref_resolver_factory, | 116 self.ref_resolver_factory, |
122 svn_constants.PUBLIC_TEMPLATE_PATH, | 117 svn_constants.PUBLIC_TEMPLATE_PATH, |
123 svn_constants.PRIVATE_TEMPLATE_PATH, | 118 svn_constants.PRIVATE_TEMPLATE_PATH, |
124 base_path) | 119 base_path) |
125 | 120 |
126 self.api_data_source_factory.SetTemplateDataSource( | 121 self.api_data_source_factory.SetTemplateDataSource( |
127 self.template_data_source_factory) | 122 self.template_data_source_factory) |
128 | 123 |
129 self.example_zipper = ExampleZipper( | 124 self.example_zipper = ExampleZipper( |
130 self.compiled_host_fs_factory, | 125 self.compiled_host_fs_factory, |
131 svn_constants.DOCS_PATH) | 126 svn_constants.DOCS_PATH) |
132 | 127 |
133 self.path_canonicalizer = PathCanonicalizer( | 128 self.path_canonicalizer = PathCanonicalizer(self.compiled_host_fs_factory) |
134 channel, | |
135 self.compiled_host_fs_factory) | |
136 | 129 |
137 # TODO(kalman): delete content cache. | 130 # TODO(kalman): delete content cache. |
138 self.content_cache = self.compiled_host_fs_factory.CreateIdentity( | 131 self.content_cache = self.compiled_host_fs_factory.CreateIdentity( |
139 ServerInstance) | 132 ServerInstance) |
140 | 133 |
141 self.redirector = Redirector( | 134 self.redirector = Redirector( |
142 self.compiled_host_fs_factory, | 135 self.compiled_host_fs_factory, |
143 self.host_file_system, | 136 self.host_file_system, |
144 svn_constants.PUBLIC_TEMPLATE_PATH) | 137 svn_constants.PUBLIC_TEMPLATE_PATH) |
145 | 138 |
146 @staticmethod | 139 @staticmethod |
147 def ForTest(file_system): | 140 def ForTest(file_system): |
148 object_store_creator = ObjectStoreCreator.ForTest() | 141 object_store_creator = ObjectStoreCreator.ForTest() |
149 return ServerInstance('test', | 142 return ServerInstance(object_store_creator, |
150 object_store_creator, | |
151 file_system, | 143 file_system, |
152 EmptyDirFileSystem(), | 144 EmptyDirFileSystem(), |
153 '', | 145 '', |
154 CompiledFileSystem.Factory(file_system, | 146 CompiledFileSystem.Factory(file_system, |
155 object_store_creator), | 147 object_store_creator), |
156 TestBranchUtility.CreateWithCannedData(), | 148 TestBranchUtility.CreateWithCannedData(), |
157 HostFileSystemCreator.ForTest(file_system, | 149 HostFileSystemCreator.ForTest(file_system, |
158 object_store_creator)) | 150 object_store_creator)) |
159 | 151 |
160 @staticmethod | 152 @staticmethod |
161 def ForLocal(): | 153 def ForLocal(): |
162 channel = 'trunk' | 154 object_store_creator = ObjectStoreCreator(start_empty=False, |
163 object_store_creator = ObjectStoreCreator(channel, | |
164 start_empty=False, | |
165 store_type=TestObjectStore) | 155 store_type=TestObjectStore) |
166 host_file_system_creator = HostFileSystemCreator.ForLocal( | 156 host_file_system_creator = HostFileSystemCreator.ForLocal( |
167 object_store_creator) | 157 object_store_creator) |
168 trunk_file_system = host_file_system_creator.Create('trunk') | 158 trunk_file_system = host_file_system_creator.Create() |
169 return ServerInstance( | 159 return ServerInstance( |
170 channel, | |
171 object_store_creator, | 160 object_store_creator, |
172 trunk_file_system, | 161 trunk_file_system, |
173 EmptyDirFileSystem(), | 162 EmptyDirFileSystem(), |
174 '', | 163 '', |
175 CompiledFileSystem.Factory(trunk_file_system, object_store_creator), | 164 CompiledFileSystem.Factory(trunk_file_system, object_store_creator), |
176 TestBranchUtility.CreateWithCannedData(), | 165 TestBranchUtility.CreateWithCannedData(), |
177 host_file_system_creator) | 166 host_file_system_creator) |
OLD | NEW |