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 |
45 STATIC_DIR_PREFIX = 'docs/server2' | 42 STATIC_DIR_PREFIX = 'docs/server2' |
46 EXTENSIONS_PATH = 'chrome/common/extensions' | 43 EXTENSIONS_PATH = 'chrome/common/extensions' |
47 DOCS_PATH = 'docs' | 44 DOCS_PATH = 'docs' |
48 API_PATH = 'api' | 45 API_PATH = 'api' |
49 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' | 46 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
50 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' | 47 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' |
51 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' | 48 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
52 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' | 49 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
53 EXAMPLES_PATH = DOCS_PATH + '/examples' | 50 EXAMPLES_PATH = DOCS_PATH + '/examples' |
54 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH | 51 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH |
55 | 52 |
56 # Global cache of instances because Handler is recreated for every request. | 53 # Global cache of instances because Handler is recreated for every request. |
57 SERVER_INSTANCES = {} | 54 SERVER_INSTANCES = {} |
58 | 55 |
59 def _GetInstanceForBranch(branch, local_path): | 56 def _GetInstanceForBranch(branch, local_path): |
60 if branch in SERVER_INSTANCES: | 57 if branch in SERVER_INSTANCES: |
61 return SERVER_INSTANCES[branch] | 58 return SERVER_INSTANCES[branch] |
62 if branch == 'local': | 59 if branch == 'local': |
63 file_system = LocalFileSystem(local_path) | 60 file_system = LocalFileSystem(local_path) |
64 else: | 61 else: |
65 fetcher = AppEngineUrlFetcher( | 62 fetcher = AppEngineUrlFetcher( |
66 _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH) | 63 _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH) |
67 file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), | 64 file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), |
68 AppEngineMemcache(branch)) | 65 AppEngineMemcache(branch)) |
69 | 66 |
| 67 github_file_system = GithubFileSystem( |
| 68 AppEngineUrlFetcher(url_constants.GITHUB_URL), |
| 69 AppEngineMemcache('github'), |
| 70 AppEngineBlobstore()) |
| 71 github_cache_builder = FileSystemCache.Builder(github_file_system) |
| 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 if real_path == '': | 121 if real_path == '': |
(...skipping 14 matching lines...) Expand all Loading... |
131 self._NavigateToPath('stable/samples.html') | 136 self._NavigateToPath('stable/samples.html') |
132 return | 137 return |
133 | 138 |
134 # Redirect paths like "directory" to "directory/". This is so relative file | 139 # Redirect paths like "directory" to "directory/". This is so relative file |
135 # paths will know to treat this as a directory. | 140 # paths will know to treat this as a directory. |
136 if os.path.splitext(path)[1] == '' and path[-1] != '/': | 141 if os.path.splitext(path)[1] == '' and path[-1] != '/': |
137 self.redirect(path + '/') | 142 self.redirect(path + '/') |
138 path = path.replace('/chrome/extensions/', '') | 143 path = path.replace('/chrome/extensions/', '') |
139 path = path.strip('/') | 144 path = path.strip('/') |
140 self._NavigateToPath(path) | 145 self._NavigateToPath(path) |
OLD | NEW |