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

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 _IsBinaryMimetype(mimetype): 40 def _IsBinaryMimetype(mimetype):
39 return any(mimetype.startswith(prefix) 41 return any(mimetype.startswith(prefix)
40 for prefix in ['audio', 'image', 'video']) 42 for prefix in ['audio', 'image', 'video'])
41 43
42 def _IsSamplesDisabled(): 44 def _IsSamplesDisabled():
43 return IsDevServer() 45 return IsDevServer()
44 46
45 class ServerInstance(object): 47 class ServerInstance(object):
46 # Lazily create so we don't create github file systems unnecessarily in 48 # Lazily create so we don't create github file systems unnecessarily in
47 # tests. 49 # tests.
48 branch_utility = None 50 branch_utility = None
49 github_file_system = None 51 github_file_system = None
50 52
51 @staticmethod 53 @staticmethod
52 @memoize 54 @memoize
53 def GetOrCreateOffline(channel): 55 def GetOrCreateOffline(channel, branch_path=None):
54 '''Gets/creates a local ServerInstance, meaning that only resources local to 56 '''Gets/creates a local ServerInstance, meaning that only resources local to
55 the server - memcache, object store, etc, are queried. This amounts to not 57 the server - memcache, object store, etc, are queried. This amounts to not
56 setting up the subversion nor github file systems. 58 setting up the subversion nor github file systems.
57 ''' 59 '''
58 branch_utility = ServerInstance._GetOrCreateBranchUtility() 60 branch_utility = ServerInstance._GetOrCreateBranchUtility()
59 branch = branch_utility.GetBranchNumberForChannelName(channel) 61 branch = branch_utility.GetBranchNumberForChannelName(channel)
60 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), 62 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(),
61 branch) 63 branch)
62 # 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
63 # for the caches to exist. 65 # for the caches to exist.
64 return ServerInstance( 66 return ServerInstance(
65 channel, 67 channel,
68 branch_path,
66 object_store_creator_factory, 69 object_store_creator_factory,
67 CachingFileSystem(OfflineFileSystem(SubversionFileSystem), 70 CachingFileSystem(OfflineFileSystem(SubversionFileSystem),
68 object_store_creator_factory), 71 object_store_creator_factory),
69 # TODO(kalman): convert GithubFileSystem to be wrappable in a 72 # TODO(kalman): convert GithubFileSystem to be wrappable in a
70 # CachingFileSystem so that it can be replaced with an 73 # CachingFileSystem so that it can be replaced with an
71 # OfflineFileSystem. Currently GFS doesn't set the child versions of 74 # OfflineFileSystem. Currently GFS doesn't set the child versions of
72 # stat requests so it doesn't. 75 # stat requests so it doesn't.
73 ServerInstance._GetOrCreateGithubFileSystem()) 76 ServerInstance._GetOrCreateGithubFileSystem())
74 77
75 @staticmethod 78 @staticmethod
76 def CreateOnline(channel): 79 def CreateOnline(channel, branch_path=None, issue=None):
77 '''Creates/creates an online server instance, meaning that both local and 80 '''Creates/creates an online server instance, meaning that both local and
78 subversion/github resources are queried. 81 subversion/github resources are queried.
79 ''' 82 '''
80 branch_utility = ServerInstance._GetOrCreateBranchUtility() 83 branch_utility = ServerInstance._GetOrCreateBranchUtility()
81 branch = branch_utility.GetBranchNumberForChannelName(channel) 84 branch = branch_utility.GetBranchNumberForChannelName(channel)
82 85
83 if branch == 'trunk': 86 if branch == 'trunk':
84 svn_url = '/'.join((url_constants.SVN_TRUNK_URL, 87 svn_url = '/'.join((url_constants.SVN_TRUNK_URL,
85 'src', 88 'src',
86 svn_constants.EXTENSIONS_PATH)) 89 svn_constants.EXTENSIONS_PATH))
87 else: 90 else:
88 svn_url = '/'.join((url_constants.SVN_BRANCH_URL, 91 svn_url = '/'.join((url_constants.SVN_BRANCH_URL,
89 branch, 92 branch,
90 'src', 93 'src',
91 svn_constants.EXTENSIONS_PATH)) 94 svn_constants.EXTENSIONS_PATH))
92 95
93 viewvc_url = svn_url.replace(url_constants.SVN_URL, 96 viewvc_url = svn_url.replace(url_constants.SVN_URL,
94 url_constants.VIEWVC_URL) 97 url_constants.VIEWVC_URL)
95 98
96 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(), 99 object_store_creator_factory = ObjectStoreCreator.Factory(GetAppVersion(),
97 branch, 100 branch,
98 start_empty=True) 101 start_empty=True)
99 102
100 svn_file_system = CachingFileSystem( 103 svn_file_system = CachingFileSystem(
101 SubversionFileSystem(AppEngineUrlFetcher(svn_url), 104 SubversionFileSystem(AppEngineUrlFetcher(svn_url),
102 AppEngineUrlFetcher(viewvc_url)), 105 AppEngineUrlFetcher(viewvc_url)),
103 object_store_creator_factory) 106 object_store_creator_factory)
104 107
108 if issue is not None:
109 object_store_creator_factory = ObjectStoreCreator.Factory(
110 GetAppVersion(),
111 branch,
not at google - send to devlin 2013/04/30 15:37:42 this shouldn't actually use the branch, we're only
方觉(Fang Jue) 2013/05/01 15:27:25 Done.
112 start_empty=True,
113 persistent=False,
114 more={'issue': issue})
not at google - send to devlin 2013/04/30 15:37:42 and I guess you wouldn't need issue:issue here - h
方觉(Fang Jue) 2013/05/01 15:27:25 Done.
115 rietveld_patcher = RietveldPatcher(
116 svn_constants.EXTENSIONS_PATH,
117 issue,
118 AppEngineUrlFetcher(url_constants.CODEREVIEW_SERVER),
119 object_store_creator_factory)
120 svn_file_system = PatchedFileSystem(svn_file_system,
121 rietveld_patcher)
122
105 return ServerInstance(channel, 123 return ServerInstance(channel,
124 branch_path,
106 object_store_creator_factory, 125 object_store_creator_factory,
107 svn_file_system, 126 svn_file_system,
108 ServerInstance._GetOrCreateGithubFileSystem()) 127 ServerInstance._GetOrCreateGithubFileSystem())
109 128
110 @staticmethod 129 @staticmethod
111 def CreateForTest(file_system): 130 def CreateForTest(file_system):
112 return ServerInstance('test', 131 return ServerInstance('test',
132 None,
113 ObjectStoreCreator.TestFactory(), 133 ObjectStoreCreator.TestFactory(),
114 file_system, 134 file_system,
115 None) 135 None)
116 136
117 @staticmethod 137 @staticmethod
118 def _GetOrCreateBranchUtility(): 138 def _GetOrCreateBranchUtility():
119 if ServerInstance.branch_utility is None: 139 if ServerInstance.branch_utility is None:
120 ServerInstance.branch_utility = BranchUtility( 140 ServerInstance.branch_utility = BranchUtility(
121 url_constants.OMAHA_PROXY_URL, 141 url_constants.OMAHA_PROXY_URL,
122 AppEngineUrlFetcher()) 142 AppEngineUrlFetcher())
123 return ServerInstance.branch_utility 143 return ServerInstance.branch_utility
124 144
125 @staticmethod 145 @staticmethod
126 def _GetOrCreateGithubFileSystem(): 146 def _GetOrCreateGithubFileSystem():
127 # Initialising github is pointless if samples are disabled, since it's only 147 # Initialising github is pointless if samples are disabled, since it's only
128 # used for apps samples. 148 # used for apps samples.
129 if ServerInstance.github_file_system is None: 149 if ServerInstance.github_file_system is None:
130 if _IsSamplesDisabled(): 150 if _IsSamplesDisabled():
131 ServerInstance.github_file_system = EmptyDirFileSystem() 151 ServerInstance.github_file_system = EmptyDirFileSystem()
132 else: 152 else:
133 ServerInstance.github_file_system = GithubFileSystem( 153 ServerInstance.github_file_system = GithubFileSystem(
134 AppEngineUrlFetcher(url_constants.GITHUB_URL), 154 AppEngineUrlFetcher(url_constants.GITHUB_URL),
135 AppEngineBlobstore()) 155 AppEngineBlobstore())
136 return ServerInstance.github_file_system 156 return ServerInstance.github_file_system
137 157
138 def __init__(self, 158 def __init__(self,
139 channel, 159 channel,
160 branch_path,
140 object_store_creator_factory, 161 object_store_creator_factory,
141 svn_file_system, 162 svn_file_system,
142 github_file_system): 163 github_file_system):
143 self.svn_file_system = svn_file_system 164 self.svn_file_system = svn_file_system
144 165
145 self.github_file_system = github_file_system 166 self.github_file_system = github_file_system
146 167
147 self.compiled_fs_factory = CompiledFileSystem.Factory( 168 self.compiled_fs_factory = CompiledFileSystem.Factory(
148 svn_file_system, 169 svn_file_system,
149 object_store_creator_factory) 170 object_store_creator_factory)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 self.template_data_source_factory = TemplateDataSource.Factory( 216 self.template_data_source_factory = TemplateDataSource.Factory(
196 channel, 217 channel,
197 self.api_data_source_factory, 218 self.api_data_source_factory,
198 self.api_list_data_source_factory, 219 self.api_list_data_source_factory,
199 self.intro_data_source_factory, 220 self.intro_data_source_factory,
200 self.samples_data_source_factory, 221 self.samples_data_source_factory,
201 self.sidenav_data_source_factory, 222 self.sidenav_data_source_factory,
202 self.compiled_fs_factory, 223 self.compiled_fs_factory,
203 self.ref_resolver_factory, 224 self.ref_resolver_factory,
204 svn_constants.PUBLIC_TEMPLATE_PATH, 225 svn_constants.PUBLIC_TEMPLATE_PATH,
205 svn_constants.PRIVATE_TEMPLATE_PATH) 226 svn_constants.PRIVATE_TEMPLATE_PATH,
227 branch_path)
206 228
207 self.example_zipper = ExampleZipper( 229 self.example_zipper = ExampleZipper(
208 self.compiled_fs_factory, 230 self.compiled_fs_factory,
209 svn_constants.DOCS_PATH) 231 svn_constants.DOCS_PATH)
210 232
211 self.path_canonicalizer = PathCanonicalizer( 233 self.path_canonicalizer = PathCanonicalizer(
212 channel, 234 channel,
213 self.compiled_fs_factory) 235 self.compiled_fs_factory)
214 236
215 self.content_cache = self.compiled_fs_factory.GetOrCreateIdentity() 237 self.content_cache = self.compiled_fs_factory.GetOrCreateIdentity()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 270
249 response.headers['x-frame-options'] = 'sameorigin' 271 response.headers['x-frame-options'] = 'sameorigin'
250 if content is None: 272 if content is None:
251 response.set_status(404); 273 response.set_status(404);
252 response.out.write(templates.Render('404')) 274 response.out.write(templates.Render('404'))
253 else: 275 else:
254 if not content: 276 if not content:
255 logging.error('%s had empty content' % path) 277 logging.error('%s had empty content' % path)
256 response.headers['cache-control'] = 'max-age=300' 278 response.headers['cache-control'] = 'max-age=300'
257 response.out.write(content) 279 response.out.write(content)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698