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

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

Issue 148293018: Docserver: Make the .html extension unnecessary for content pages, for example, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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 import logging 5 import logging
6 import posixpath
6 import traceback 7 import traceback
7 8
8 from app_yaml_helper import AppYamlHelper 9 from app_yaml_helper import AppYamlHelper
9 from appengine_wrappers import ( 10 from appengine_wrappers import (
10 GetAppVersion, IsDeadlineExceededError, logservice) 11 GetAppVersion, IsDeadlineExceededError, logservice)
11 from branch_utility import BranchUtility 12 from branch_utility import BranchUtility
12 from compiled_file_system import CompiledFileSystem 13 from compiled_file_system import CompiledFileSystem
13 from data_source_registry import CreateDataSources 14 from data_source_registry import CreateDataSources
14 from environment import IsDevServer 15 from environment import IsDevServer
15 from extensions_paths import EXAMPLES, PUBLIC_TEMPLATES, STATIC_DOCS 16 from extensions_paths import EXAMPLES, PUBLIC_TEMPLATES, STATIC_DOCS
16 from file_system_util import CreateURLsFromPaths 17 from file_system_util import CreateURLsFromPaths
17 from future import Gettable, Future 18 from future import Gettable, Future
18 from github_file_system_provider import GithubFileSystemProvider 19 from github_file_system_provider import GithubFileSystemProvider
19 from host_file_system_provider import HostFileSystemProvider 20 from host_file_system_provider import HostFileSystemProvider
20 from object_store_creator import ObjectStoreCreator 21 from object_store_creator import ObjectStoreCreator
21 from render_servlet import RenderServlet 22 from render_servlet import RenderServlet
22 from server_instance import ServerInstance 23 from server_instance import ServerInstance
23 from servlet import Servlet, Request, Response 24 from servlet import Servlet, Request, Response
25 from special_paths import WEBMASTER_PROOF
24 from timer import Timer, TimerClosure 26 from timer import Timer, TimerClosure
25 27
26 28
27 class _SingletonRenderServletDelegate(RenderServlet.Delegate): 29 class _SingletonRenderServletDelegate(RenderServlet.Delegate):
28 def __init__(self, server_instance): 30 def __init__(self, server_instance):
29 self._server_instance = server_instance 31 self._server_instance = server_instance
30 32
31 def CreateServerInstance(self): 33 def CreateServerInstance(self):
32 return self._server_instance 34 return self._server_instance
33 35
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 # TODO(kalman): IMPORTANT. This sometimes throws an exception, breaking 137 # TODO(kalman): IMPORTANT. This sometimes throws an exception, breaking
136 # everything. Need retry logic at the fetcher level. 138 # everything. Need retry logic at the fetcher level.
137 server_instance = self._GetSafeServerInstance() 139 server_instance = self._GetSafeServerInstance()
138 trunk_fs = server_instance.host_file_system_provider.GetTrunk() 140 trunk_fs = server_instance.host_file_system_provider.GetTrunk()
139 141
140 def render(path): 142 def render(path):
141 request = Request(path, self._request.host, self._request.headers) 143 request = Request(path, self._request.host, self._request.headers)
142 delegate = _SingletonRenderServletDelegate(server_instance) 144 delegate = _SingletonRenderServletDelegate(server_instance)
143 return RenderServlet(request, delegate).Get() 145 return RenderServlet(request, delegate).Get()
144 146
145 def request_files_in_dir(path, prefix=''): 147 def request_files_in_dir(path, prefix='', strip_ext=None):
146 '''Requests every file found under |path| in this host file system, with 148 '''Requests every file found under |path| in this host file system, with
147 a request prefix of |prefix|. 149 a request prefix of |prefix|. |strip_ext| is an optional list of file
150 extensions that should be stripped from paths before requesting.
148 ''' 151 '''
149 files = [name for name, _ in CreateURLsFromPaths(trunk_fs, path, prefix)] 152 def maybe_strip_ext(name):
153 if name == WEBMASTER_PROOF or not strip_ext:
154 return name
155 base, ext = posixpath.splitext(name)
156 return base if ext in strip_ext else name
157 files = [maybe_strip_ext(name)
158 for name, _ in CreateURLsFromPaths(trunk_fs, path, prefix)]
150 return _RequestEachItem(path, files, render) 159 return _RequestEachItem(path, files, render)
151 160
152 results = [] 161 results = []
153 162
154 try: 163 try:
155 # Start running the hand-written Cron methods first; they can be run in 164 # Start running the hand-written Cron methods first; they can be run in
156 # parallel. They are resolved at the end. 165 # parallel. They are resolved at the end.
157 def run_cron_for_future(target): 166 def run_cron_for_future(target):
158 title = target.__class__.__name__ 167 title = target.__class__.__name__
159 future, init_timer = TimerClosure(target.Cron) 168 future, init_timer = TimerClosure(target.Cron)
(...skipping 21 matching lines...) Expand all
181 title = 'initializing %s parallel Cron targets' % len(targets) 190 title = 'initializing %s parallel Cron targets' % len(targets)
182 _cronlog.info(title) 191 _cronlog.info(title)
183 timer = Timer() 192 timer = Timer()
184 try: 193 try:
185 cron_futures = [run_cron_for_future(target) for target in targets] 194 cron_futures = [run_cron_for_future(target) for target in targets]
186 finally: 195 finally:
187 _cronlog.info('%s took %s' % (title, timer.Stop().FormatElapsed())) 196 _cronlog.info('%s took %s' % (title, timer.Stop().FormatElapsed()))
188 197
189 # Rendering the public templates will also pull in all of the private 198 # Rendering the public templates will also pull in all of the private
190 # templates. 199 # templates.
191 results.append(request_files_in_dir(PUBLIC_TEMPLATES)) 200 results.append(request_files_in_dir(PUBLIC_TEMPLATES,
201 strip_ext=('.html', '.md')))
192 202
193 # Rendering the public templates will have pulled in the .js and 203 # Rendering the public templates will have pulled in the .js and
194 # manifest.json files (for listing examples on the API reference pages), 204 # manifest.json files (for listing examples on the API reference pages),
195 # but there are still images, CSS, etc. 205 # but there are still images, CSS, etc.
196 results.append(request_files_in_dir(STATIC_DOCS, prefix='static')) 206 results.append(request_files_in_dir(STATIC_DOCS, prefix='static'))
197 207
198 # Samples are too expensive to run on the dev server, where there is no 208 # Samples are too expensive to run on the dev server, where there is no
199 # parallel fetch. 209 # parallel fetch.
200 if not IsDevServer(): 210 if not IsDevServer():
201 # Fetch each individual sample file. 211 # Fetch each individual sample file.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 branch_utility = self._delegate.CreateBranchUtility(object_store_creator) 295 branch_utility = self._delegate.CreateBranchUtility(object_store_creator)
286 host_file_system_provider = self._delegate.CreateHostFileSystemProvider( 296 host_file_system_provider = self._delegate.CreateHostFileSystemProvider(
287 object_store_creator, max_trunk_revision=revision) 297 object_store_creator, max_trunk_revision=revision)
288 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( 298 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider(
289 object_store_creator) 299 object_store_creator)
290 return ServerInstance(object_store_creator, 300 return ServerInstance(object_store_creator,
291 CompiledFileSystem.Factory(object_store_creator), 301 CompiledFileSystem.Factory(object_store_creator),
292 branch_utility, 302 branch_utility,
293 host_file_system_provider, 303 host_file_system_provider,
294 github_file_system_provider) 304 github_file_system_provider)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698