| 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 sys | 6 import sys |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 # Add the original server location to sys.path so we are able to import | 9 # Add the original server location to sys.path so we are able to import |
| 10 # modules from there. | 10 # modules from there. |
| 11 SERVER_PATH = 'chrome/common/extensions/docs/server2' | 11 SERVER_PATH = 'chrome/common/extensions/docs/server2' |
| 12 if os.path.abspath(SERVER_PATH) not in sys.path: | 12 if os.path.abspath(SERVER_PATH) not in sys.path: |
| 13 sys.path.append(os.path.abspath(SERVER_PATH)) | 13 sys.path.append(os.path.abspath(SERVER_PATH)) |
| 14 | 14 |
| 15 import branch_utility | 15 import branch_utility |
| 16 import urlfetch | 16 import urlfetch |
| 17 | 17 |
| 18 from google.appengine.ext import webapp | 18 from google.appengine.ext import webapp |
| 19 from google.appengine.ext.webapp.util import run_wsgi_app | 19 from google.appengine.ext.webapp.util import run_wsgi_app |
| 20 | 20 |
| 21 from api_data_source import APIDataSource | 21 from api_data_source import APIDataSource |
| 22 from fetcher_cache import FetcherCache | 22 from fetcher_cache import FetcherCache |
| 23 from intro_data_source import IntroDataSource | 23 from intro_data_source import IntroDataSource |
| 24 from local_fetcher import LocalFetcher | 24 from local_fetcher import LocalFetcher |
| 25 from samples_data_source import SamplesDataSource |
| 25 from server_instance import ServerInstance | 26 from server_instance import ServerInstance |
| 26 from subversion_fetcher import SubversionFetcher | 27 from subversion_fetcher import SubversionFetcher |
| 27 from template_data_source import TemplateDataSource | 28 from template_data_source import TemplateDataSource |
| 29 from example_zipper import ExampleZipper |
| 28 | 30 |
| 29 EXTENSIONS_PATH = 'chrome/common/extensions' | 31 EXTENSIONS_PATH = 'chrome/common/extensions' |
| 30 DOCS_PATH = 'docs' | 32 DOCS_PATH = 'docs' |
| 31 API_PATH = 'api' | 33 API_PATH = 'api' |
| 32 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' | 34 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
| 33 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' | 35 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
| 34 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' | 36 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
| 37 EXAMPLES_PATH = 'examples' |
| 38 FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH |
| 35 | 39 |
| 36 # The branch that the server will default to when no branch is specified in the | 40 # The branch that the server will default to when no branch is specified in the |
| 37 # URL. This is necessary because it is not possible to pass flags to the script | 41 # URL. This is necessary because it is not possible to pass flags to the script |
| 38 # handler. | 42 # handler. |
| 39 DEFAULT_BRANCH = 'local' | 43 DEFAULT_BRANCH = 'local' |
| 40 | 44 |
| 41 # Global cache of instances because the Server is recreated for every request. | 45 # Global cache of instances because the Server is recreated for every request. |
| 42 SERVER_INSTANCES = {} | 46 SERVER_INSTANCES = {} |
| 43 | 47 |
| 44 class Server(webapp.RequestHandler): | 48 class Server(webapp.RequestHandler): |
| 45 def _GetInstanceForBranch(self, branch): | 49 def _GetInstanceForBranch(self, branch): |
| 46 if branch in SERVER_INSTANCES: | 50 if branch in SERVER_INSTANCES: |
| 47 return SERVER_INSTANCES[branch] | 51 return SERVER_INSTANCES[branch] |
| 48 if branch == 'local': | 52 if branch == 'local': |
| 49 fetcher = LocalFetcher(EXTENSIONS_PATH) | 53 fetcher = LocalFetcher(EXTENSIONS_PATH) |
| 50 # No cache for local doc server. | 54 # No cache for local doc server. |
| 51 cache_timeout_seconds = 0 | 55 cache_timeout_seconds = 0 |
| 52 else: | 56 else: |
| 53 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) | 57 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) |
| 54 cache_timeout_seconds = 300 | 58 cache_timeout_seconds = 300 |
| 55 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) | 59 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) |
| 56 api_data_source = APIDataSource(cache_builder, API_PATH) | 60 api_data_source = APIDataSource(cache_builder, API_PATH) |
| 57 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH) | 61 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH) |
| 62 samples_data_source = SamplesDataSource(fetcher, |
| 63 cache_builder, |
| 64 EXAMPLES_PATH) |
| 58 template_data_source = TemplateDataSource( | 65 template_data_source = TemplateDataSource( |
| 59 branch, | 66 branch, |
| 60 api_data_source, | 67 api_data_source, |
| 61 intro_data_source, | 68 intro_data_source, |
| 69 samples_data_source, |
| 62 cache_builder, | 70 cache_builder, |
| 63 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) | 71 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) |
| 72 example_zipper = ExampleZipper(fetcher, |
| 73 cache_builder, |
| 74 DOCS_PATH, |
| 75 EXAMPLES_PATH) |
| 64 SERVER_INSTANCES[branch] = ServerInstance( | 76 SERVER_INSTANCES[branch] = ServerInstance( |
| 65 template_data_source, | 77 template_data_source, |
| 78 example_zipper, |
| 66 cache_builder) | 79 cache_builder) |
| 67 return SERVER_INSTANCES[branch] | 80 return SERVER_INSTANCES[branch] |
| 68 | 81 |
| 69 def _HandleRequest(self, path): | 82 def _HandleRequest(self, path): |
| 70 channel_name, real_path = ( | 83 channel_name, real_path = ( |
| 71 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH)) | 84 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH)) |
| 72 branch = branch_utility.GetBranchNumberForChannelName(channel_name, | 85 branch = branch_utility.GetBranchNumberForChannelName(channel_name, |
| 73 urlfetch) | 86 urlfetch) |
| 74 if real_path == '': | 87 if real_path == '': |
| 75 real_path = 'index.html' | 88 real_path = 'index.html' |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 | 100 |
| 88 def main(): | 101 def main(): |
| 89 handlers = [ | 102 handlers = [ |
| 90 ('/.*', Server), | 103 ('/.*', Server), |
| 91 ] | 104 ] |
| 92 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) | 105 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) |
| 93 | 106 |
| 94 | 107 |
| 95 if __name__ == '__main__': | 108 if __name__ == '__main__': |
| 96 main() | 109 main() |
| OLD | NEW |