| 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 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 gcs_file_system_provider import CloudStorageFileSystemProvider | 19 from gcs_file_system_provider import CloudStorageFileSystemProvider |
| 19 from github_file_system_provider import GithubFileSystemProvider | 20 from github_file_system_provider import GithubFileSystemProvider |
| 20 from host_file_system_provider import HostFileSystemProvider | 21 from host_file_system_provider import HostFileSystemProvider |
| 21 from object_store_creator import ObjectStoreCreator | 22 from object_store_creator import ObjectStoreCreator |
| 22 from render_servlet import RenderServlet | 23 from render_servlet import RenderServlet |
| 23 from server_instance import ServerInstance | 24 from server_instance import ServerInstance |
| 24 from servlet import Servlet, Request, Response | 25 from servlet import Servlet, Request, Response |
| 26 from special_paths import SITE_VERIFICATION_FILE |
| 25 from timer import Timer, TimerClosure | 27 from timer import Timer, TimerClosure |
| 26 | 28 |
| 27 | 29 |
| 28 class _SingletonRenderServletDelegate(RenderServlet.Delegate): | 30 class _SingletonRenderServletDelegate(RenderServlet.Delegate): |
| 29 def __init__(self, server_instance): | 31 def __init__(self, server_instance): |
| 30 self._server_instance = server_instance | 32 self._server_instance = server_instance |
| 31 | 33 |
| 32 def CreateServerInstance(self): | 34 def CreateServerInstance(self): |
| 33 return self._server_instance | 35 return self._server_instance |
| 34 | 36 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 # TODO(kalman): IMPORTANT. This sometimes throws an exception, breaking | 141 # TODO(kalman): IMPORTANT. This sometimes throws an exception, breaking |
| 140 # everything. Need retry logic at the fetcher level. | 142 # everything. Need retry logic at the fetcher level. |
| 141 server_instance = self._GetSafeServerInstance() | 143 server_instance = self._GetSafeServerInstance() |
| 142 trunk_fs = server_instance.host_file_system_provider.GetTrunk() | 144 trunk_fs = server_instance.host_file_system_provider.GetTrunk() |
| 143 | 145 |
| 144 def render(path): | 146 def render(path): |
| 145 request = Request(path, self._request.host, self._request.headers) | 147 request = Request(path, self._request.host, self._request.headers) |
| 146 delegate = _SingletonRenderServletDelegate(server_instance) | 148 delegate = _SingletonRenderServletDelegate(server_instance) |
| 147 return RenderServlet(request, delegate).Get() | 149 return RenderServlet(request, delegate).Get() |
| 148 | 150 |
| 149 def request_files_in_dir(path, prefix=''): | 151 def request_files_in_dir(path, prefix='', strip_ext=None): |
| 150 '''Requests every file found under |path| in this host file system, with | 152 '''Requests every file found under |path| in this host file system, with |
| 151 a request prefix of |prefix|. | 153 a request prefix of |prefix|. |strip_ext| is an optional list of file |
| 154 extensions that should be stripped from paths before requesting. |
| 152 ''' | 155 ''' |
| 153 files = [name for name, _ in CreateURLsFromPaths(trunk_fs, path, prefix)] | 156 def maybe_strip_ext(name): |
| 157 if name == SITE_VERIFICATION_FILE or not strip_ext: |
| 158 return name |
| 159 base, ext = posixpath.splitext(name) |
| 160 return base if ext in strip_ext else name |
| 161 files = [maybe_strip_ext(name) |
| 162 for name, _ in CreateURLsFromPaths(trunk_fs, path, prefix)] |
| 154 return _RequestEachItem(path, files, render) | 163 return _RequestEachItem(path, files, render) |
| 155 | 164 |
| 156 results = [] | 165 results = [] |
| 157 | 166 |
| 158 try: | 167 try: |
| 159 # Start running the hand-written Cron methods first; they can be run in | 168 # Start running the hand-written Cron methods first; they can be run in |
| 160 # parallel. They are resolved at the end. | 169 # parallel. They are resolved at the end. |
| 161 def run_cron_for_future(target): | 170 def run_cron_for_future(target): |
| 162 title = target.__class__.__name__ | 171 title = target.__class__.__name__ |
| 163 future, init_timer = TimerClosure(target.Cron) | 172 future, init_timer = TimerClosure(target.Cron) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 185 title = 'initializing %s parallel Cron targets' % len(targets) | 194 title = 'initializing %s parallel Cron targets' % len(targets) |
| 186 _cronlog.info(title) | 195 _cronlog.info(title) |
| 187 timer = Timer() | 196 timer = Timer() |
| 188 try: | 197 try: |
| 189 cron_futures = [run_cron_for_future(target) for target in targets] | 198 cron_futures = [run_cron_for_future(target) for target in targets] |
| 190 finally: | 199 finally: |
| 191 _cronlog.info('%s took %s' % (title, timer.Stop().FormatElapsed())) | 200 _cronlog.info('%s took %s' % (title, timer.Stop().FormatElapsed())) |
| 192 | 201 |
| 193 # Rendering the public templates will also pull in all of the private | 202 # Rendering the public templates will also pull in all of the private |
| 194 # templates. | 203 # templates. |
| 195 results.append(request_files_in_dir(PUBLIC_TEMPLATES)) | 204 results.append(request_files_in_dir(PUBLIC_TEMPLATES, |
| 205 strip_ext=('.html', '.md'))) |
| 196 | 206 |
| 197 # Rendering the public templates will have pulled in the .js and | 207 # Rendering the public templates will have pulled in the .js and |
| 198 # manifest.json files (for listing examples on the API reference pages), | 208 # manifest.json files (for listing examples on the API reference pages), |
| 199 # but there are still images, CSS, etc. | 209 # but there are still images, CSS, etc. |
| 200 results.append(request_files_in_dir(STATIC_DOCS, prefix='static')) | 210 results.append(request_files_in_dir(STATIC_DOCS, prefix='static')) |
| 201 | 211 |
| 202 # Samples are too expensive to run on the dev server, where there is no | 212 # Samples are too expensive to run on the dev server, where there is no |
| 203 # parallel fetch. | 213 # parallel fetch. |
| 204 if not IsDevServer(): | 214 if not IsDevServer(): |
| 205 # Fetch each individual sample file. | 215 # Fetch each individual sample file. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( | 302 github_file_system_provider = self._delegate.CreateGithubFileSystemProvider( |
| 293 object_store_creator) | 303 object_store_creator) |
| 294 gcs_file_system_provider = self._delegate.CreateGCSFileSystemProvider( | 304 gcs_file_system_provider = self._delegate.CreateGCSFileSystemProvider( |
| 295 object_store_creator) | 305 object_store_creator) |
| 296 return ServerInstance(object_store_creator, | 306 return ServerInstance(object_store_creator, |
| 297 CompiledFileSystem.Factory(object_store_creator), | 307 CompiledFileSystem.Factory(object_store_creator), |
| 298 branch_utility, | 308 branch_utility, |
| 299 host_file_system_provider, | 309 host_file_system_provider, |
| 300 github_file_system_provider, | 310 github_file_system_provider, |
| 301 gcs_file_system_provider) | 311 gcs_file_system_provider) |
| OLD | NEW |