OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 appengine_wrappers import IsDevServer | 5 from appengine_wrappers import IsDevServer |
6 from branch_utility import BranchUtility | 6 from branch_utility import BranchUtility |
7 from caching_file_system import CachingFileSystem | 7 from caching_file_system import CachingFileSystem |
8 from compiled_file_system import CompiledFileSystem | 8 from compiled_file_system import CompiledFileSystem |
9 from empty_dir_file_system import EmptyDirFileSystem | 9 from empty_dir_file_system import EmptyDirFileSystem |
10 from github_file_system import GithubFileSystem | 10 from github_file_system import GithubFileSystem |
(...skipping 20 matching lines...) Expand all Loading... |
31 pretty soon, and it also means that legitimate 404s are caught before a round | 31 pretty soon, and it also means that legitimate 404s are caught before a round |
32 trip to SVN. | 32 trip to SVN. |
33 ''' | 33 ''' |
34 def __init__(self, delegate): | 34 def __init__(self, delegate): |
35 self._delegate = delegate | 35 self._delegate = delegate |
36 | 36 |
37 @memoize | 37 @memoize |
38 def CreateServerInstanceForChannel(self, channel): | 38 def CreateServerInstanceForChannel(self, channel): |
39 object_store_creator = ObjectStoreCreator(channel, start_empty=False) | 39 object_store_creator = ObjectStoreCreator(channel, start_empty=False) |
40 branch = (self._delegate.CreateBranchUtility(object_store_creator) | 40 branch = (self._delegate.CreateBranchUtility(object_store_creator) |
41 .GetBranchForChannel(channel)) | 41 .GetChannelInfo(channel).branch) |
42 host_file_system = CachingFileSystem( | 42 host_file_system = CachingFileSystem( |
43 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch(branch)), | 43 OfflineFileSystem(self._delegate.CreateHostFileSystemForBranch(branch)), |
44 object_store_creator) | 44 object_store_creator) |
45 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem( | 45 app_samples_file_system = self._delegate.CreateAppSamplesFileSystem( |
46 object_store_creator) | 46 object_store_creator) |
| 47 def create_file_system(branch): |
| 48 return CachingFileSystem( |
| 49 OfflineFileSystem(SubversionFileSystem.Create(branch)), |
| 50 object_store_creator) |
47 compiled_host_fs_factory = CompiledFileSystem.Factory( | 51 compiled_host_fs_factory = CompiledFileSystem.Factory( |
48 host_file_system, | 52 host_file_system, |
49 object_store_creator) | 53 object_store_creator) |
50 return ServerInstance(channel, | 54 return ServerInstance(channel, |
51 object_store_creator, | 55 object_store_creator, |
52 host_file_system, | 56 host_file_system, |
53 app_samples_file_system, | 57 app_samples_file_system, |
54 '/static' if channel == 'stable' else | 58 '/static' if channel == 'stable' else |
55 '/%s/static' % channel, | 59 '/%s/static' % channel, |
56 compiled_host_fs_factory) | 60 compiled_host_fs_factory, |
| 61 create_file_system) |
57 | 62 |
58 class InstanceServlet(object): | 63 class InstanceServlet(object): |
59 '''Servlet for running on normal AppEngine instances. | 64 '''Servlet for running on normal AppEngine instances. |
60 Create this via GetConstructor() so that cache state can be shared amongst | 65 Create this via GetConstructor() so that cache state can be shared amongst |
61 them via the memoizing Delegate. | 66 them via the memoizing Delegate. |
62 ''' | 67 ''' |
63 class Delegate(object): | 68 class Delegate(object): |
64 '''Allow runtime dependencies to be overriden for testing. | 69 '''Allow runtime dependencies to be overriden for testing. |
65 ''' | 70 ''' |
66 def CreateBranchUtility(self, object_store_creator): | 71 def CreateBranchUtility(self, object_store_creator): |
67 return BranchUtility.Create(object_store_creator) | 72 return BranchUtility.Create(object_store_creator) |
68 | 73 |
69 def CreateHostFileSystemForBranch(self, branch): | 74 def CreateHostFileSystemForBranch(self, branch): |
70 return SubversionFileSystem.Create(branch) | 75 return SubversionFileSystem.Create(branch) |
71 | 76 |
72 def CreateAppSamplesFileSystem(self, object_store_creator): | 77 def CreateAppSamplesFileSystem(self, object_store_creator): |
73 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but | 78 # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but |
74 # the cron job doesn't crawl the samples yet. | 79 # the cron job doesn't crawl the samples yet. |
75 return (EmptyDirFileSystem() if IsDevServer() else | 80 return (EmptyDirFileSystem() if IsDevServer() else |
76 GithubFileSystem.Create(object_store_creator)) | 81 GithubFileSystem.Create(object_store_creator)) |
77 | 82 |
78 @staticmethod | 83 @staticmethod |
79 def GetConstructor(delegate_for_test=None): | 84 def GetConstructor(delegate_for_test=None): |
80 render_servlet_delegate = _OfflineRenderServletDelegate( | 85 render_servlet_delegate = _OfflineRenderServletDelegate( |
81 delegate_for_test or InstanceServlet.Delegate()) | 86 delegate_for_test or InstanceServlet.Delegate()) |
82 return lambda request: RenderServlet(request, render_servlet_delegate) | 87 return lambda request: RenderServlet(request, render_servlet_delegate) |
83 | 88 |
84 # NOTE: if this were a real Servlet it would implement a Get() method, but | 89 # NOTE: if this were a real Servlet it would implement a Get() method, but |
85 # GetConstructor returns an appropriate lambda function (Request -> Servlet). | 90 # GetConstructor returns an appropriate lambda function (Request -> Servlet). |
OLD | NEW |