Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/common/extensions/docs/server2/server_instance.py

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 logging 6 import logging
7 import mimetypes 7 import mimetypes
8 import traceback 8 import traceback
9 import os 9 import os
10 10
11 from api_data_source import APIDataSource 11 from api_data_source import APIDataSource
12 from api_list_data_source import APIListDataSource 12 from api_list_data_source import APIListDataSource
13 from appengine_blobstore import AppEngineBlobstore 13 from appengine_blobstore import AppEngineBlobstore
14 from appengine_url_fetcher import AppEngineUrlFetcher 14 from appengine_url_fetcher import AppEngineUrlFetcher
15 from appengine_wrappers import GetAppVersion, IsDevServer 15 from appengine_wrappers import GetAppVersion, IsDevServer
16 from branch_utility import BranchUtility 16 from branch_utility import BranchUtility
17 from caching_file_system import CachingFileSystem 17 from caching_file_system import CachingFileSystem
18 from compiled_file_system import CompiledFileSystem 18 from compiled_file_system import CompiledFileSystem
19 from empty_dir_file_system import EmptyDirFileSystem 19 from empty_dir_file_system import EmptyDirFileSystem
20 from example_zipper import ExampleZipper 20 from example_zipper import ExampleZipper
21 from file_system import FileNotFoundError 21 from file_system import FileNotFoundError
22 from github_file_system import GithubFileSystem 22 from github_file_system import GithubFileSystem
23 from intro_data_source import IntroDataSource 23 from intro_data_source import IntroDataSource
24 from local_file_system import LocalFileSystem 24 from local_file_system import LocalFileSystem
25 from object_store_creator import ObjectStoreCreator 25 from object_store_creator import ObjectStoreCreator
26 from offline_file_system import OfflineFileSystem 26 from offline_file_system import OfflineFileSystem
27 from patched_file_system import PatchedFileSystem
27 from path_canonicalizer import PathCanonicalizer 28 from path_canonicalizer import PathCanonicalizer
28 from reference_resolver import ReferenceResolver 29 from reference_resolver import ReferenceResolver
30 from rietveld_patcher import RietveldPatcher
29 from samples_data_source import SamplesDataSource 31 from samples_data_source import SamplesDataSource
30 from sidenav_data_source import SidenavDataSource 32 from sidenav_data_source import SidenavDataSource
31 from subversion_file_system import SubversionFileSystem 33 from subversion_file_system import SubversionFileSystem
32 import svn_constants 34 import svn_constants
33 from template_data_source import TemplateDataSource 35 from template_data_source import TemplateDataSource
34 from third_party.json_schema_compiler.memoize import memoize 36 from third_party.json_schema_compiler.memoize import memoize
35 from third_party.json_schema_compiler.model import UnixName 37 from third_party.json_schema_compiler.model import UnixName
36 import url_constants 38 import url_constants
37 39
38 def _IsSamplesDisabled(): 40 def _IsSamplesDisabled():
39 return IsDevServer() 41 return IsDevServer()
40 42
41 class ServerInstance(object): 43 class ServerInstance(object):
42 # Lazily create so we don't create github file systems unnecessarily in 44 # Lazily create so we don't create github file systems unnecessarily in
43 # tests. 45 # tests.
44 branch_utility = None 46 branch_utility = None
45 github_file_system = None 47 github_file_system = None
46 48
47 @staticmethod 49 @staticmethod
48 @memoize 50 @memoize
49 def GetOrCreateOffline(channel): 51 def GetOrCreateOffline(channel, base_path=None, issue=None):
not at google - send to devlin 2013/05/03 19:12:22 After https://codereview.chromium.org/14856006 hop
50 '''Gets/creates a local ServerInstance, meaning that only resources local to 52 '''Gets/creates a local ServerInstance, meaning that only resources local to
51 the server - memcache, object store, etc, are queried. This amounts to not 53 the server - memcache, object store, etc, are queried. This amounts to not
52 setting up the subversion nor github file systems. 54 setting up the subversion nor github file systems.
53 ''' 55 '''
54 branch_utility = ServerInstance._GetOrCreateBranchUtility() 56 branch_utility = ServerInstance._GetOrCreateBranchUtility()
55 branch = branch_utility.GetBranchNumberForChannelName(channel) 57 branch = branch_utility.GetBranchNumberForChannelName(channel)
56 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), 58 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(),
57 branch) 59 branch)
60 svn_file_system = CachingFileSystem(OfflineFileSystem(SubversionFileSystem),
61 object_store_creator_factory,
62 use_existing_values=True)
63
58 # No svn nor github file systems. Rely on the crons to fill the caches, and 64 # No svn nor github file systems. Rely on the crons to fill the caches, and
59 # for the caches to exist. 65 # for the caches to exist.
60 return ServerInstance( 66 return ServerInstance._CreateWithPatch(
61 channel, 67 channel,
68 base_path,
62 object_store_creator_factory, 69 object_store_creator_factory,
63 CachingFileSystem(OfflineFileSystem(SubversionFileSystem), 70 svn_file_system,
64 object_store_creator_factory,
65 use_existing_values=True),
66 # TODO(kalman): convert GithubFileSystem to be wrappable in a 71 # TODO(kalman): convert GithubFileSystem to be wrappable in a
67 # CachingFileSystem so that it can be replaced with an 72 # CachingFileSystem so that it can be replaced with an
68 # OfflineFileSystem. Currently GFS doesn't set the child versions of 73 # OfflineFileSystem. Currently GFS doesn't set the child versions of
69 # stat requests so it doesn't. 74 # stat requests so it doesn't.
70 ServerInstance._GetOrCreateGithubFileSystem()) 75 ServerInstance._GetOrCreateGithubFileSystem(),
76 issue)
71 77
72 @staticmethod 78 @staticmethod
73 def CreateOnline(channel): 79 def CreateOnline(channel, base_path=None, issue=None):
74 '''Creates/creates an online server instance, meaning that both local and 80 '''Creates/creates an online server instance, meaning that both local and
75 subversion/github resources are queried. 81 subversion/github resources are queried.
76 ''' 82 '''
77 branch_utility = ServerInstance._GetOrCreateBranchUtility() 83 branch_utility = ServerInstance._GetOrCreateBranchUtility()
78 branch = branch_utility.GetBranchNumberForChannelName(channel) 84 branch = branch_utility.GetBranchNumberForChannelName(channel)
79 85
80 if branch == 'trunk': 86 if branch == 'trunk':
81 svn_url = '/'.join((url_constants.SVN_TRUNK_URL, 87 svn_url = '/'.join((url_constants.SVN_TRUNK_URL,
82 'src', 88 'src',
83 svn_constants.EXTENSIONS_PATH)) 89 svn_constants.EXTENSIONS_PATH))
84 else: 90 else:
85 svn_url = '/'.join((url_constants.SVN_BRANCH_URL, 91 svn_url = '/'.join((url_constants.SVN_BRANCH_URL,
86 branch, 92 branch,
87 'src', 93 'src',
88 svn_constants.EXTENSIONS_PATH)) 94 svn_constants.EXTENSIONS_PATH))
89 95
90 viewvc_url = svn_url.replace(url_constants.SVN_URL, 96 viewvc_url = svn_url.replace(url_constants.SVN_URL,
91 url_constants.VIEWVC_URL) 97 url_constants.VIEWVC_URL)
92 98
93 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), 99 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(),
94 branch) 100 branch)
95 101
96 svn_file_system = CachingFileSystem( 102 svn_file_system = CachingFileSystem(
97 SubversionFileSystem(AppEngineUrlFetcher(svn_url), 103 SubversionFileSystem(AppEngineUrlFetcher(svn_url),
98 AppEngineUrlFetcher(viewvc_url)), 104 AppEngineUrlFetcher(viewvc_url)),
99 object_store_creator_factory) 105 object_store_creator_factory)
100 106
107 return ServerInstance._CreateWithPatch(
108 channel,
109 base_path,
110 object_store_creator_factory,
111 svn_file_system,
112 ServerInstance._GetOrCreateGithubFileSystem(),
113 issue)
114
115 @staticmethod
116 def _CreateWithPatch(channel,
117 base_path,
118 object_store_creator_factory,
119 svn_file_system,
120 github_file_system,
121 issue=None):
122 if issue is not None:
123 object_store_creator_factory = ObjectStoreCreator.Factory(
124 GetAppVersion(),
125 'trunk@%s' % issue)
126 rietveld_patcher = RietveldPatcher(
127 svn_constants.EXTENSIONS_PATH,
128 issue,
129 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER),
130 object_store_creator_factory)
131 svn_file_system = PatchedFileSystem(svn_file_system,
132 rietveld_patcher)
101 return ServerInstance(channel, 133 return ServerInstance(channel,
134 base_path,
102 object_store_creator_factory, 135 object_store_creator_factory,
103 svn_file_system, 136 svn_file_system,
104 ServerInstance._GetOrCreateGithubFileSystem()) 137 github_file_system)
105 138
106 @staticmethod 139 @staticmethod
107 def CreateForTest(file_system): 140 def CreateForTest(file_system):
108 return ServerInstance('test', 141 return ServerInstance('test',
142 None,
109 ObjectStoreCreator.TestFactory(), 143 ObjectStoreCreator.TestFactory(),
110 file_system, 144 file_system,
111 None) 145 None)
112 146
113 @staticmethod 147 @staticmethod
114 def _GetOrCreateBranchUtility(): 148 def _GetOrCreateBranchUtility():
115 if ServerInstance.branch_utility is None: 149 if ServerInstance.branch_utility is None:
116 ServerInstance.branch_utility = BranchUtility( 150 ServerInstance.branch_utility = BranchUtility(
117 url_constants.OMAHA_PROXY_URL, 151 url_constants.OMAHA_PROXY_URL,
118 AppEngineUrlFetcher()) 152 AppEngineUrlFetcher())
119 return ServerInstance.branch_utility 153 return ServerInstance.branch_utility
120 154
121 @staticmethod 155 @staticmethod
122 def _GetOrCreateGithubFileSystem(): 156 def _GetOrCreateGithubFileSystem():
123 # Initialising github is pointless if samples are disabled, since it's only 157 # Initialising github is pointless if samples are disabled, since it's only
124 # used for apps samples. 158 # used for apps samples.
125 if ServerInstance.github_file_system is None: 159 if ServerInstance.github_file_system is None:
126 if _IsSamplesDisabled(): 160 if _IsSamplesDisabled():
127 ServerInstance.github_file_system = EmptyDirFileSystem() 161 ServerInstance.github_file_system = EmptyDirFileSystem()
128 else: 162 else:
129 ServerInstance.github_file_system = GithubFileSystem( 163 ServerInstance.github_file_system = GithubFileSystem(
130 AppEngineUrlFetcher(url_constants.GITHUB_URL), 164 AppEngineUrlFetcher(url_constants.GITHUB_URL),
131 AppEngineBlobstore()) 165 AppEngineBlobstore())
132 return ServerInstance.github_file_system 166 return ServerInstance.github_file_system
133 167
134 def __init__(self, 168 def __init__(self,
135 channel, 169 channel,
170 base_path,
136 object_store_creator_factory, 171 object_store_creator_factory,
137 svn_file_system, 172 svn_file_system,
138 github_file_system): 173 github_file_system):
139 self.svn_file_system = svn_file_system 174 self.svn_file_system = svn_file_system
140 175
141 self.github_file_system = github_file_system 176 self.github_file_system = github_file_system
142 177
143 self.compiled_fs_factory = CompiledFileSystem.Factory( 178 self.compiled_fs_factory = CompiledFileSystem.Factory(
144 svn_file_system, 179 svn_file_system,
145 object_store_creator_factory) 180 object_store_creator_factory)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 self.template_data_source_factory = TemplateDataSource.Factory( 226 self.template_data_source_factory = TemplateDataSource.Factory(
192 channel, 227 channel,
193 self.api_data_source_factory, 228 self.api_data_source_factory,
194 self.api_list_data_source_factory, 229 self.api_list_data_source_factory,
195 self.intro_data_source_factory, 230 self.intro_data_source_factory,
196 self.samples_data_source_factory, 231 self.samples_data_source_factory,
197 self.sidenav_data_source_factory, 232 self.sidenav_data_source_factory,
198 self.compiled_fs_factory, 233 self.compiled_fs_factory,
199 self.ref_resolver_factory, 234 self.ref_resolver_factory,
200 svn_constants.PUBLIC_TEMPLATE_PATH, 235 svn_constants.PUBLIC_TEMPLATE_PATH,
201 svn_constants.PRIVATE_TEMPLATE_PATH) 236 svn_constants.PRIVATE_TEMPLATE_PATH,
237 base_path)
202 238
203 self.example_zipper = ExampleZipper( 239 self.example_zipper = ExampleZipper(
204 self.compiled_fs_factory, 240 self.compiled_fs_factory,
205 svn_constants.DOCS_PATH) 241 svn_constants.DOCS_PATH)
206 242
207 self.path_canonicalizer = PathCanonicalizer( 243 self.path_canonicalizer = PathCanonicalizer(
208 channel, 244 channel,
209 self.compiled_fs_factory) 245 self.compiled_fs_factory)
210 246
211 self.content_cache = self.compiled_fs_factory.CreateIdentity(ServerInstance) 247 self.content_cache = self.compiled_fs_factory.CreateIdentity(ServerInstance)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698