OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 | 9 |
10 # Add the original server location to sys.path so we are able to import | 10 # Add the original server location to sys.path so we are able to import |
11 # modules from there. | 11 # modules from there. |
12 SERVER_PATH = 'chrome/common/extensions/docs/server2' | 12 SERVER_PATH = 'chrome/common/extensions/docs/server2' |
13 if os.path.abspath(SERVER_PATH) not in sys.path: | 13 if os.path.abspath(SERVER_PATH) not in sys.path: |
14 sys.path.append(os.path.abspath(SERVER_PATH)) | 14 sys.path.append(os.path.abspath(SERVER_PATH)) |
15 | 15 |
16 from google.appengine.ext import webapp | 16 from google.appengine.ext import webapp |
17 from google.appengine.api import memcache | 17 from google.appengine.api import memcache |
18 from google.appengine.ext.webapp.util import run_wsgi_app | 18 from google.appengine.ext.webapp.util import run_wsgi_app |
19 | 19 |
20 from api_data_source import APIDataSource | 20 from api_data_source import APIDataSource |
21 from api_list_data_source import APIListDataSource | 21 from api_list_data_source import APIListDataSource |
22 from appengine_memcache import AppEngineMemcache | 22 from appengine_memcache import AppEngineMemcache |
| 23 from appengine_url_fetcher import AppEngineUrlFetcher |
23 from branch_utility import BranchUtility | 24 from branch_utility import BranchUtility |
24 from example_zipper import ExampleZipper | 25 from example_zipper import ExampleZipper |
25 from file_system_cache import FileSystemCache | 26 from file_system_cache import FileSystemCache |
26 from intro_data_source import IntroDataSource | 27 from intro_data_source import IntroDataSource |
27 from local_file_system import LocalFileSystem | 28 from local_file_system import LocalFileSystem |
28 from memcache_file_system import MemcacheFileSystem | 29 from memcache_file_system import MemcacheFileSystem |
| 30 from memcache_url_fetcher import MemcacheUrlFetcher |
29 from samples_data_source import SamplesDataSource | 31 from samples_data_source import SamplesDataSource |
30 from server_instance import ServerInstance | 32 from server_instance import ServerInstance |
31 from subversion_file_system import SubversionFileSystem | 33 from subversion_file_system import SubversionFileSystem |
32 from template_data_source import TemplateDataSource | 34 from template_data_source import TemplateDataSource |
33 from appengine_url_fetcher import AppEngineUrlFetcher | 35 from zip_file_system import ZipFileSystem |
34 | 36 |
35 SVN_URL = 'http://src.chromium.org/chrome' | 37 SVN_URL = 'http://src.chromium.org/chrome' |
36 TRUNK_URL = SVN_URL + '/trunk' | 38 TRUNK_URL = SVN_URL + '/trunk' |
37 BRANCH_URL = SVN_URL + '/branches' | 39 BRANCH_URL = SVN_URL + '/branches' |
38 | 40 |
39 EXTENSIONS_PATH = 'chrome/common/extensions' | 41 EXTENSIONS_PATH = 'chrome/common/extensions' |
40 DOCS_PATH = 'docs' | 42 DOCS_PATH = 'docs' |
41 API_PATH = 'api' | 43 API_PATH = 'api' |
42 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' | 44 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
43 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' | 45 ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' |
44 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' | 46 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
45 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' | 47 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
46 EXAMPLES_PATH = DOCS_PATH + '/examples' | 48 EXAMPLES_PATH = DOCS_PATH + '/examples' |
47 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH | 49 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH |
48 | 50 |
| 51 GITHUB_URL = 'https://api.github.com/repos/GoogleChrome/chrome-app-samples' |
| 52 |
49 # The branch that the server will default to when no branch is specified in the | 53 # The branch that the server will default to when no branch is specified in the |
50 # URL. This is necessary because it is not possible to pass flags to the script | 54 # URL. This is necessary because it is not possible to pass flags to the script |
51 # handler. | 55 # handler. |
52 DEFAULT_BRANCH = 'local' | 56 DEFAULT_BRANCH = 'local' |
53 | 57 |
54 # Global cache of instances because Handler is recreated for every request. | 58 # Global cache of instances because Handler is recreated for every request. |
55 SERVER_INSTANCES = {} | 59 SERVER_INSTANCES = {} |
56 | 60 |
57 OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json' | 61 OMAHA_PROXY_URL = 'http://omahaproxy.appspot.com/json' |
58 BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL, | 62 BRANCH_UTILITY = BranchUtility(OMAHA_PROXY_URL, |
59 DEFAULT_BRANCH, | 63 DEFAULT_BRANCH, |
60 AppEngineUrlFetcher(''), | 64 AppEngineUrlFetcher(''), |
61 AppEngineMemcache('branch_utility', memcache)) | 65 AppEngineMemcache('branch_utility', memcache)) |
62 | 66 |
63 def _GetURLFromBranch(branch): | 67 def _GetURLFromBranch(branch): |
64 if branch == 'trunk': | 68 if branch == 'trunk': |
65 return TRUNK_URL + '/src' | 69 return TRUNK_URL + '/src' |
66 return BRANCH_URL + '/' + branch + '/src' | 70 return BRANCH_URL + '/' + branch + '/src' |
67 | 71 |
68 class Handler(webapp.RequestHandler): | 72 class Handler(webapp.RequestHandler): |
69 def _GetInstanceForBranch(self, branch): | 73 def _GetInstanceForBranch(self, branch): |
70 if branch in SERVER_INSTANCES: | 74 if branch in SERVER_INSTANCES: |
71 return SERVER_INSTANCES[branch] | 75 return SERVER_INSTANCES[branch] |
| 76 appengine_memcache = AppEngineMemcache(branch, memcache) |
72 if branch == 'local': | 77 if branch == 'local': |
73 file_system = LocalFileSystem(EXTENSIONS_PATH) | 78 file_system = LocalFileSystem(EXTENSIONS_PATH) |
74 else: | 79 else: |
75 fetcher = AppEngineUrlFetcher( | 80 fetcher = AppEngineUrlFetcher( |
76 _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH) | 81 _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH) |
77 file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), | 82 file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), |
78 AppEngineMemcache(branch, memcache)) | 83 appengine_memcache) |
79 | 84 zip_file_system = ZipFileSystem( |
| 85 MemcacheUrlFetcher(appengine_memcache, GITHUB_URL)) |
| 86 zip_cache_builder = FileSystemCache.Builder(zip_file_system) |
80 cache_builder = FileSystemCache.Builder(file_system) | 87 cache_builder = FileSystemCache.Builder(file_system) |
81 api_data_source = APIDataSource(cache_builder, API_PATH) | 88 api_data_source = APIDataSource(cache_builder, API_PATH) |
82 api_list_data_source = APIListDataSource(cache_builder, | 89 api_list_data_source = APIListDataSource(cache_builder, |
83 file_system, | 90 file_system, |
84 API_PATH, | 91 API_PATH, |
85 PUBLIC_TEMPLATE_PATH) | 92 PUBLIC_TEMPLATE_PATH) |
86 intro_data_source = IntroDataSource(cache_builder, | 93 intro_data_source = IntroDataSource(cache_builder, |
87 [INTRO_PATH, ARTICLE_PATH]) | 94 [INTRO_PATH, ARTICLE_PATH]) |
88 samples_data_source_factory = SamplesDataSource.Factory(branch, | 95 samples_data_source_factory = SamplesDataSource.Factory(branch, |
89 file_system, | 96 file_system, |
| 97 zip_file_system, |
90 cache_builder, | 98 cache_builder, |
| 99 zip_cache_builder, |
91 EXAMPLES_PATH) | 100 EXAMPLES_PATH) |
92 template_data_source_factory = TemplateDataSource.Factory( | 101 template_data_source_factory = TemplateDataSource.Factory( |
93 branch, | 102 branch, |
94 api_data_source, | 103 api_data_source, |
95 api_list_data_source, | 104 api_list_data_source, |
96 intro_data_source, | 105 intro_data_source, |
97 samples_data_source_factory, | 106 samples_data_source_factory, |
98 cache_builder, | 107 cache_builder, |
99 PUBLIC_TEMPLATE_PATH, | 108 PUBLIC_TEMPLATE_PATH, |
100 PRIVATE_TEMPLATE_PATH) | 109 PRIVATE_TEMPLATE_PATH) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 # TODO: This leaks Server instances when branch bumps. | 141 # TODO: This leaks Server instances when branch bumps. |
133 self._GetInstanceForBranch(branch).Get(real_path, | 142 self._GetInstanceForBranch(branch).Get(real_path, |
134 self.request, | 143 self.request, |
135 self.response) | 144 self.response) |
136 | 145 |
137 def main(): | 146 def main(): |
138 run_wsgi_app(webapp.WSGIApplication([('/.*', Handler)], debug=False)) | 147 run_wsgi_app(webapp.WSGIApplication([('/.*', Handler)], debug=False)) |
139 | 148 |
140 if __name__ == '__main__': | 149 if __name__ == '__main__': |
141 main() | 150 main() |
OLD | NEW |