Chromium Code Reviews| 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 time | 7 import time |
| 7 import traceback | 8 import traceback |
| 8 | 9 |
| 9 from app_yaml_helper import AppYamlHelper | 10 from app_yaml_helper import AppYamlHelper |
| 10 from appengine_wrappers import ( | 11 from appengine_wrappers import ( |
| 11 GetAppVersion, DeadlineExceededError, IsDevServer, logservice) | 12 GetAppVersion, DeadlineExceededError, IsDevServer, logservice) |
| 12 from branch_utility import BranchUtility | 13 from branch_utility import BranchUtility |
| 13 from caching_file_system import CachingFileSystem | 14 from caching_file_system import CachingFileSystem |
| 14 from compiled_file_system import CompiledFileSystem | 15 from compiled_file_system import CompiledFileSystem |
| 15 from empty_dir_file_system import EmptyDirFileSystem | 16 from empty_dir_file_system import EmptyDirFileSystem |
| 16 from github_file_system import GithubFileSystem | 17 from github_file_system import GithubFileSystem |
| 17 from object_store_creator import ObjectStoreCreator | 18 from object_store_creator import ObjectStoreCreator |
| 18 from render_servlet import RenderServlet | 19 from render_servlet import RenderServlet |
| 19 from server_instance import ServerInstance | 20 from server_instance import ServerInstance |
| 20 from servlet import Servlet, Request, Response | 21 from servlet import Servlet, Request, Response |
| 21 from subversion_file_system import SubversionFileSystem | 22 from subversion_file_system import SubversionFileSystem |
| 22 import svn_constants | 23 import svn_constants |
| 23 from third_party.json_schema_compiler.memoize import memoize | 24 from third_party.json_schema_compiler.memoize import memoize |
| 24 | 25 |
| 26 def CreateURLsFromPaths(file_system, dirpath, urlprefix): | |
| 27 ''' Create a mapping between all of the files in the directory of |dirpath| | |
|
not at google - send to devlin
2013/07/09 00:17:32
'''Yields a tuple (url, path) for every file in |d
jshumway
2013/07/17 00:49:55
Done.
| |
| 28 and their corrisponding URLs, with the URLs as keys. | |
| 29 ''' | |
| 30 for root, dirs, files in file_system.Walk(dirpath): | |
|
not at google - send to devlin
2013/07/09 00:17:32
s/dirs/_/
jshumway
2013/07/17 00:49:55
Done.
| |
| 31 for f in files: | |
| 32 url = posixpath.join(urlprefix, root[len(dirpath) + 1:], f) | |
| 33 yield url, '%s/%s' % (root, f) | |
| 34 | |
| 25 class _SingletonRenderServletDelegate(RenderServlet.Delegate): | 35 class _SingletonRenderServletDelegate(RenderServlet.Delegate): |
| 26 def __init__(self, server_instance): | 36 def __init__(self, server_instance): |
| 27 self._server_instance = server_instance | 37 self._server_instance = server_instance |
| 28 | 38 |
| 29 def CreateServerInstanceForChannel(self, channel): | 39 def CreateServerInstanceForChannel(self, channel): |
| 30 return self._server_instance | 40 return self._server_instance |
| 31 | 41 |
| 32 class CronServlet(Servlet): | 42 class CronServlet(Servlet): |
| 33 '''Servlet which runs a cron job. | 43 '''Servlet which runs a cron job. |
| 34 ''' | 44 ''' |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 server_instance = self._GetSafeServerInstance() | 89 server_instance = self._GetSafeServerInstance() |
| 80 | 90 |
| 81 def get_via_render_servlet(path): | 91 def get_via_render_servlet(path): |
| 82 request = Request(path, self._request.host, self._request.headers) | 92 request = Request(path, self._request.host, self._request.headers) |
| 83 delegate = _SingletonRenderServletDelegate(server_instance) | 93 delegate = _SingletonRenderServletDelegate(server_instance) |
| 84 return RenderServlet(request, delegate).Get() | 94 return RenderServlet(request, delegate).Get() |
| 85 | 95 |
| 86 def run_cron_for_dir(d, path_prefix=''): | 96 def run_cron_for_dir(d, path_prefix=''): |
| 87 success = True | 97 success = True |
| 88 start_time = time.time() | 98 start_time = time.time() |
| 89 # TODO(jshumway): use server_instance.host_file_system.Walk. | |
| 90 # TODO(kalman): delete me where it's set. | 99 # TODO(kalman): delete me where it's set. |
|
not at google - send to devlin
2013/07/09 00:17:32
could you move this todo into server_instance on c
jshumway
2013/07/17 00:49:55
Done.
| |
| 91 files = [f for f in server_instance.content_cache.GetFromFileListing(d) | 100 files = dict( |
| 92 if not f.endswith('/') and f != 'redirects.json'] | 101 CreateURLsFromPaths(server_instance.host_file_system, d, path_prefix)) |
| 93 logging.info('cron/%s: rendering %s files from %s...' % ( | 102 logging.info('cron/%s: rendering %s files from %s...' % ( |
| 94 channel, len(files), d)) | 103 channel, len(files), d)) |
| 95 try: | 104 try: |
| 96 for i, f in enumerate(files): | 105 for i, path in enumerate(files): |
| 97 error = None | 106 error = None |
| 98 path = '%s%s' % (path_prefix, f) | |
| 99 try: | 107 try: |
| 100 response = get_via_render_servlet(path) | 108 response = get_via_render_servlet(path) |
| 101 if response.status != 200: | 109 if response.status != 200: |
| 102 error = 'Got %s response' % response.status | 110 error = 'Got %s response' % response.status |
| 103 except DeadlineExceededError: | 111 except DeadlineExceededError: |
| 104 logging.error( | 112 logging.error( |
| 105 'cron/%s: deadline exceeded rendering %s (%s of %s): %s' % ( | 113 'cron/%s: deadline exceeded rendering %s (%s of %s): %s' % ( |
| 106 channel, path, i + 1, len(files), traceback.format_exc())) | 114 channel, path, i + 1, len(files), traceback.format_exc())) |
| 107 raise | 115 raise |
| 108 except error: | 116 except error: |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 object_store_creator) | 238 object_store_creator) |
| 231 compiled_host_fs_factory = CompiledFileSystem.Factory( | 239 compiled_host_fs_factory = CompiledFileSystem.Factory( |
| 232 host_file_system, | 240 host_file_system, |
| 233 object_store_creator) | 241 object_store_creator) |
| 234 return ServerInstance(channel, | 242 return ServerInstance(channel, |
| 235 object_store_creator, | 243 object_store_creator, |
| 236 host_file_system, | 244 host_file_system, |
| 237 app_samples_file_system, | 245 app_samples_file_system, |
| 238 '' if channel == 'stable' else '/%s' % channel, | 246 '' if channel == 'stable' else '/%s' % channel, |
| 239 compiled_host_fs_factory) | 247 compiled_host_fs_factory) |
| OLD | NEW |