| OLD | NEW |
| 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 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 from appengine_wrappers import webapp | 9 from appengine_wrappers import webapp |
| 10 from appengine_wrappers import memcache | 10 from appengine_wrappers import memcache |
| 11 from appengine_wrappers import urlfetch | 11 from appengine_wrappers import urlfetch |
| 12 | 12 |
| 13 from api_data_source import APIDataSource | 13 from api_data_source import APIDataSource |
| 14 from api_list_data_source import APIListDataSource | 14 from api_list_data_source import APIListDataSource |
| 15 from appengine_blobstore import AppEngineBlobstore |
| 15 from appengine_memcache import AppEngineMemcache | 16 from appengine_memcache import AppEngineMemcache |
| 16 from appengine_url_fetcher import AppEngineUrlFetcher | 17 from appengine_url_fetcher import AppEngineUrlFetcher |
| 17 from branch_utility import BranchUtility | 18 from branch_utility import BranchUtility |
| 18 from example_zipper import ExampleZipper | 19 from example_zipper import ExampleZipper |
| 19 from file_system_cache import FileSystemCache | 20 from file_system_cache import FileSystemCache |
| 21 from github_file_system import GithubFileSystem |
| 20 from intro_data_source import IntroDataSource | 22 from intro_data_source import IntroDataSource |
| 21 from local_file_system import LocalFileSystem | 23 from local_file_system import LocalFileSystem |
| 22 from memcache_file_system import MemcacheFileSystem | 24 from memcache_file_system import MemcacheFileSystem |
| 23 from samples_data_source import SamplesDataSource | 25 from samples_data_source import SamplesDataSource |
| 24 from server_instance import ServerInstance | 26 from server_instance import ServerInstance |
| 25 from subversion_file_system import SubversionFileSystem | 27 from subversion_file_system import SubversionFileSystem |
| 26 from template_data_source import TemplateDataSource | 28 from template_data_source import TemplateDataSource |
| 27 from appengine_url_fetcher import AppEngineUrlFetcher | 29 import url_constants |
| 28 | 30 |
| 29 # The branch that the server will default to when no branch is specified in the | 31 # The branch that the server will default to when no branch is specified in the |
| 30 # URL. This is necessary because it is not possible to pass flags to the script | 32 # URL. This is necessary because it is not possible to pass flags to the script |
| 31 # handler. | 33 # handler. |
| 32 DEFAULT_BRANCH = 'local' | 34 DEFAULT_BRANCH = 'local' |
| 33 | 35 |
| 34 SVN_URL = 'http://src.chromium.org/chrome' | |
| 35 TRUNK_URL = SVN_URL + '/trunk' | |
| 36 BRANCH_URL = SVN_URL + '/branches' | |
| 37 | |
| 38 OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json' | |
| 39 BRANCH_UTILITY_MEMCACHE = AppEngineMemcache('branch_utility') | 36 BRANCH_UTILITY_MEMCACHE = AppEngineMemcache('branch_utility') |
| 40 BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL, | 37 BRANCH_UTILITY = BranchUtility(url_constants.OMAHA_PROXY_URL, |
| 41 DEFAULT_BRANCH, | 38 DEFAULT_BRANCH, |
| 42 AppEngineUrlFetcher(''), | 39 AppEngineUrlFetcher(''), |
| 43 BRANCH_UTILITY_MEMCACHE) | 40 BRANCH_UTILITY_MEMCACHE) |
| 44 | 41 |
| 42 GITHUB_FILE_SYSTEM = GithubFileSystem( |
| 43 AppEngineUrlFetcher(url_constants.GITHUB_URL), |
| 44 AppEngineMemcache('github'), |
| 45 AppEngineBlobstore()) |
| 46 GITHUB_CACHE_BUILDER = FileSystemCache.Builder(GITHUB_FILE_SYSTEM) |
| 47 |
| 45 STATIC_DIR_PREFIX = 'docs/server2' | 48 STATIC_DIR_PREFIX = 'docs/server2' |
| 46 EXTENSIONS_PATH = 'chrome/common/extensions' | 49 EXTENSIONS_PATH = 'chrome/common/extensions' |
| 47 DOCS_PATH = 'docs' | 50 DOCS_PATH = 'docs' |
| 48 API_PATH = 'api' | 51 API_PATH = 'api' |
| 49 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' | 52 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
| 50 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' | 53 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' |
| 51 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' | 54 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
| 52 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' | 55 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
| 53 EXAMPLES_PATH = DOCS_PATH + '/examples' | 56 EXAMPLES_PATH = DOCS_PATH + '/examples' |
| 54 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH | 57 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH |
| (...skipping 14 matching lines...) Expand all Loading... |
| 69 | 72 |
| 70 cache_builder = FileSystemCache.Builder(file_system) | 73 cache_builder = FileSystemCache.Builder(file_system) |
| 71 api_list_data_source = APIListDataSource(cache_builder, | 74 api_list_data_source = APIListDataSource(cache_builder, |
| 72 file_system, | 75 file_system, |
| 73 API_PATH, | 76 API_PATH, |
| 74 PUBLIC_TEMPLATE_PATH) | 77 PUBLIC_TEMPLATE_PATH) |
| 75 intro_data_source = IntroDataSource(cache_builder, | 78 intro_data_source = IntroDataSource(cache_builder, |
| 76 [INTRO_PATH, ARTICLE_PATH]) | 79 [INTRO_PATH, ARTICLE_PATH]) |
| 77 samples_data_source_factory = SamplesDataSource.Factory(branch, | 80 samples_data_source_factory = SamplesDataSource.Factory(branch, |
| 78 file_system, | 81 file_system, |
| 82 GITHUB_FILE_SYSTEM, |
| 79 cache_builder, | 83 cache_builder, |
| 84 GITHUB_CACHE_BUILDER, |
| 80 EXAMPLES_PATH) | 85 EXAMPLES_PATH) |
| 81 api_data_source_factory = APIDataSource.Factory(cache_builder, | 86 api_data_source_factory = APIDataSource.Factory(cache_builder, |
| 82 API_PATH, | 87 API_PATH, |
| 83 samples_data_source_factory) | 88 samples_data_source_factory) |
| 84 template_data_source_factory = TemplateDataSource.Factory( | 89 template_data_source_factory = TemplateDataSource.Factory( |
| 85 branch, | 90 branch, |
| 86 api_data_source_factory, | 91 api_data_source_factory, |
| 87 api_list_data_source, | 92 api_list_data_source, |
| 88 intro_data_source, | 93 intro_data_source, |
| 89 samples_data_source_factory, | 94 samples_data_source_factory, |
| 90 cache_builder, | 95 cache_builder, |
| 91 PUBLIC_TEMPLATE_PATH, | 96 PUBLIC_TEMPLATE_PATH, |
| 92 PRIVATE_TEMPLATE_PATH) | 97 PRIVATE_TEMPLATE_PATH) |
| 93 example_zipper = ExampleZipper(file_system, | 98 example_zipper = ExampleZipper(file_system, |
| 94 cache_builder, | 99 cache_builder, |
| 95 DOCS_PATH, | 100 DOCS_PATH, |
| 96 EXAMPLES_PATH) | 101 EXAMPLES_PATH) |
| 97 SERVER_INSTANCES[branch] = ServerInstance( | 102 SERVER_INSTANCES[branch] = ServerInstance( |
| 98 template_data_source_factory, | 103 template_data_source_factory, |
| 99 example_zipper, | 104 example_zipper, |
| 100 cache_builder) | 105 cache_builder) |
| 101 return SERVER_INSTANCES[branch] | 106 return SERVER_INSTANCES[branch] |
| 102 | 107 |
| 103 def _GetURLFromBranch(branch): | 108 def _GetURLFromBranch(branch): |
| 104 if branch == 'trunk': | 109 if branch == 'trunk': |
| 105 return TRUNK_URL + '/src' | 110 return url_constants.SVN_TRUNK_URL + '/src' |
| 106 return BRANCH_URL + '/' + branch + '/src' | 111 return url_constants.SVN_BRANCH_URL + '/' + branch + '/src' |
| 107 | 112 |
| 108 class Handler(webapp.RequestHandler): | 113 class Handler(webapp.RequestHandler): |
| 109 def __init__(self, request, response, local_path=EXTENSIONS_PATH): | 114 def __init__(self, request, response, local_path=EXTENSIONS_PATH): |
| 110 self._local_path = local_path | 115 self._local_path = local_path |
| 111 super(Handler, self).__init__(request, response) | 116 super(Handler, self).__init__(request, response) |
| 112 | 117 |
| 113 def _NavigateToPath(self, path): | 118 def _NavigateToPath(self, path): |
| 114 channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path) | 119 channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path) |
| 115 branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) | 120 branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) |
| 116 # TODO: Detect that these are directories and serve index.html out of them. | 121 # TODO: Detect that these are directories and serve index.html out of them. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 134 self._NavigateToPath('stable/extensions/samples.html') | 139 self._NavigateToPath('stable/extensions/samples.html') |
| 135 return | 140 return |
| 136 | 141 |
| 137 # Redirect paths like "directory" to "directory/". This is so relative file | 142 # Redirect paths like "directory" to "directory/". This is so relative file |
| 138 # paths will know to treat this as a directory. | 143 # paths will know to treat this as a directory. |
| 139 if os.path.splitext(path)[1] == '' and path[-1] != '/': | 144 if os.path.splitext(path)[1] == '' and path[-1] != '/': |
| 140 self.redirect(path + '/') | 145 self.redirect(path + '/') |
| 141 path = path.replace('/chrome/', '') | 146 path = path.replace('/chrome/', '') |
| 142 path = path.strip('/') | 147 path = path.strip('/') |
| 143 self._NavigateToPath(path) | 148 self._NavigateToPath(path) |
| OLD | NEW |