| 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_memcache import AppEngineMemcache | 15 from appengine_memcache import AppEngineMemcache |
| 16 from appengine_url_fetcher import AppEngineUrlFetcher | 16 from appengine_url_fetcher import AppEngineUrlFetcher |
| 17 from branch_utility import BranchUtility | 17 from branch_utility import BranchUtility |
| 18 from example_zipper import ExampleZipper | 18 from example_zipper import ExampleZipper |
| 19 from file_system_cache import FileSystemCache | 19 from file_system_cache import FileSystemCache |
| 20 from github_file_system import GithubFileSystem |
| 20 from intro_data_source import IntroDataSource | 21 from intro_data_source import IntroDataSource |
| 21 from local_file_system import LocalFileSystem | 22 from local_file_system import LocalFileSystem |
| 22 from memcache_file_system import MemcacheFileSystem | 23 from memcache_file_system import MemcacheFileSystem |
| 23 from samples_data_source import SamplesDataSource | 24 from samples_data_source import SamplesDataSource |
| 24 from server_instance import ServerInstance | 25 from server_instance import ServerInstance |
| 25 from subversion_file_system import SubversionFileSystem | 26 from subversion_file_system import SubversionFileSystem |
| 26 from template_data_source import TemplateDataSource | 27 from template_data_source import TemplateDataSource |
| 27 from appengine_url_fetcher import AppEngineUrlFetcher | 28 import url_constants |
| 28 | 29 |
| 29 # The branch that the server will default to when no branch is specified in the | 30 # 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 | 31 # URL. This is necessary because it is not possible to pass flags to the script |
| 31 # handler. | 32 # handler. |
| 32 DEFAULT_BRANCH = 'local' | 33 DEFAULT_BRANCH = 'local' |
| 33 | 34 |
| 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') | 35 BRANCH_UTILITY_MEMCACHE = AppEngineMemcache('branch_utility') |
| 40 BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL, | 36 BRANCH_UTILITY = BranchUtility(url_constants.OMAHA_PROXY_URL, |
| 41 DEFAULT_BRANCH, | 37 DEFAULT_BRANCH, |
| 42 AppEngineUrlFetcher(''), | 38 AppEngineUrlFetcher(''), |
| 43 BRANCH_UTILITY_MEMCACHE) | 39 BRANCH_UTILITY_MEMCACHE) |
| 44 | 40 |
| 45 STATIC_DIR_PREFIX = 'docs/server2' | 41 STATIC_DIR_PREFIX = 'docs/server2' |
| 46 EXTENSIONS_PATH = 'chrome/common/extensions' | 42 EXTENSIONS_PATH = 'chrome/common/extensions' |
| 47 DOCS_PATH = 'docs' | 43 DOCS_PATH = 'docs' |
| 48 API_PATH = 'api' | 44 API_PATH = 'api' |
| 49 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' | 45 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
| 50 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' | 46 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' |
| 51 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' | 47 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
| 52 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' | 48 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
| 53 EXAMPLES_PATH = DOCS_PATH + '/examples' | 49 EXAMPLES_PATH = DOCS_PATH + '/examples' |
| 54 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH | 50 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH |
| 55 | 51 |
| 56 # Global cache of instances because Handler is recreated for every request. | 52 # Global cache of instances because Handler is recreated for every request. |
| 57 SERVER_INSTANCES = {} | 53 SERVER_INSTANCES = {} |
| 58 | 54 |
| 59 def _GetInstanceForBranch(branch, local_path): | 55 def _GetInstanceForBranch(branch, local_path): |
| 60 if branch in SERVER_INSTANCES: | 56 if branch in SERVER_INSTANCES: |
| 61 return SERVER_INSTANCES[branch] | 57 return SERVER_INSTANCES[branch] |
| 62 if branch == 'local': | 58 if branch == 'local': |
| 63 file_system = LocalFileSystem(local_path) | 59 file_system = LocalFileSystem(local_path) |
| 64 else: | 60 else: |
| 65 fetcher = AppEngineUrlFetcher( | 61 fetcher = AppEngineUrlFetcher( |
| 66 _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH) | 62 _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH) |
| 67 file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), | 63 file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), |
| 68 AppEngineMemcache(branch)) | 64 AppEngineMemcache(branch)) |
| 69 | 65 |
| 66 github_file_system = MemcacheFileSystem( |
| 67 GithubFileSystem(AppEngineUrlFetcher(url_constants.GITHUB_URL)), |
| 68 AppEngineMemcache('github')) |
| 69 github_cache_builder = FileSystemCache.Builder(github_file_system) |
| 70 |
| 70 cache_builder = FileSystemCache.Builder(file_system) | 71 cache_builder = FileSystemCache.Builder(file_system) |
| 71 api_data_source = APIDataSource(cache_builder, API_PATH) | 72 api_data_source = APIDataSource(cache_builder, API_PATH) |
| 72 api_list_data_source = APIListDataSource(cache_builder, | 73 api_list_data_source = APIListDataSource(cache_builder, |
| 73 file_system, | 74 file_system, |
| 74 API_PATH, | 75 API_PATH, |
| 75 PUBLIC_TEMPLATE_PATH) | 76 PUBLIC_TEMPLATE_PATH) |
| 76 intro_data_source = IntroDataSource(cache_builder, | 77 intro_data_source = IntroDataSource(cache_builder, |
| 77 [INTRO_PATH, ARTICLE_PATH]) | 78 [INTRO_PATH, ARTICLE_PATH]) |
| 78 samples_data_source_factory = SamplesDataSource.Factory(branch, | 79 samples_data_source_factory = SamplesDataSource.Factory(branch, |
| 79 file_system, | 80 file_system, |
| 81 github_file_system, |
| 80 cache_builder, | 82 cache_builder, |
| 83 github_cache_builder, |
| 81 EXAMPLES_PATH) | 84 EXAMPLES_PATH) |
| 82 template_data_source_factory = TemplateDataSource.Factory( | 85 template_data_source_factory = TemplateDataSource.Factory( |
| 83 branch, | 86 branch, |
| 84 api_data_source, | 87 api_data_source, |
| 85 api_list_data_source, | 88 api_list_data_source, |
| 86 intro_data_source, | 89 intro_data_source, |
| 87 samples_data_source_factory, | 90 samples_data_source_factory, |
| 88 cache_builder, | 91 cache_builder, |
| 89 PUBLIC_TEMPLATE_PATH, | 92 PUBLIC_TEMPLATE_PATH, |
| 90 PRIVATE_TEMPLATE_PATH) | 93 PRIVATE_TEMPLATE_PATH) |
| 91 example_zipper = ExampleZipper(file_system, | 94 example_zipper = ExampleZipper(file_system, |
| 92 cache_builder, | 95 cache_builder, |
| 93 DOCS_PATH, | 96 DOCS_PATH, |
| 94 EXAMPLES_PATH) | 97 EXAMPLES_PATH) |
| 95 SERVER_INSTANCES[branch] = ServerInstance( | 98 SERVER_INSTANCES[branch] = ServerInstance( |
| 96 template_data_source_factory, | 99 template_data_source_factory, |
| 97 example_zipper, | 100 example_zipper, |
| 98 cache_builder) | 101 cache_builder) |
| 99 return SERVER_INSTANCES[branch] | 102 return SERVER_INSTANCES[branch] |
| 100 | 103 |
| 101 def _GetURLFromBranch(branch): | 104 def _GetURLFromBranch(branch): |
| 102 if branch == 'trunk': | 105 if branch == 'trunk': |
| 103 return TRUNK_URL + '/src' | 106 return url_constants.SVN_TRUNK_URL + '/src' |
| 104 return BRANCH_URL + '/' + branch + '/src' | 107 return url_constants.SVN_BRANCH_URL + '/' + branch + '/src' |
| 105 | 108 |
| 106 class Handler(webapp.RequestHandler): | 109 class Handler(webapp.RequestHandler): |
| 107 def __init__(self, request, response, local_path=EXTENSIONS_PATH): | 110 def __init__(self, request, response, local_path=EXTENSIONS_PATH): |
| 108 self._local_path = local_path | 111 self._local_path = local_path |
| 109 super(Handler, self).__init__(request, response) | 112 super(Handler, self).__init__(request, response) |
| 110 | 113 |
| 111 def _NavigateToPath(self, path): | 114 def _NavigateToPath(self, path): |
| 112 channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path) | 115 channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path) |
| 113 branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) | 116 branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) |
| 114 if real_path == '': | 117 if real_path == '': |
| (...skipping 14 matching lines...) Expand all Loading... |
| 129 self._NavigateToPath('stable/samples.html') | 132 self._NavigateToPath('stable/samples.html') |
| 130 return | 133 return |
| 131 | 134 |
| 132 # Redirect paths like "directory" to "directory/". This is so relative file | 135 # Redirect paths like "directory" to "directory/". This is so relative file |
| 133 # paths will know to treat this as a directory. | 136 # paths will know to treat this as a directory. |
| 134 if os.path.splitext(path)[1] == '' and path[-1] != '/': | 137 if os.path.splitext(path)[1] == '' and path[-1] != '/': |
| 135 self.redirect(path + '/') | 138 self.redirect(path + '/') |
| 136 path = path.replace('/chrome/extensions/', '') | 139 path = path.replace('/chrome/extensions/', '') |
| 137 path = path.strip('/') | 140 path = path.strip('/') |
| 138 self._NavigateToPath(path) | 141 self._NavigateToPath(path) |
| OLD | NEW |