| 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 local_fetcher import LocalFetcher | 24 from local_fetcher import LocalFetcher |
| 24 from server_instance import ServerInstance | 25 from server_instance import ServerInstance |
| 25 from subversion_fetcher import SubversionFetcher | 26 from subversion_fetcher import SubversionFetcher |
| 26 from template_data_source import TemplateDataSource | 27 from template_data_source import TemplateDataSource |
| 27 | 28 |
| 28 EXTENSIONS_PATH = 'chrome/common/extensions' | 29 EXTENSIONS_PATH = 'chrome/common/extensions' |
| 29 DOCS_PATH = 'docs' | 30 DOCS_PATH = 'docs' |
| 30 API_PATH = 'api' | 31 API_PATH = 'api' |
| 32 INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
| 31 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' | 33 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
| 32 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' | 34 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
| 33 | 35 |
| 34 # The branch that the server will default to when no branch is specified in the | 36 # The branch that the server will default to when no branch is specified in the |
| 35 # URL. This is necessary because it is not possible to pass flags to the script | 37 # URL. This is necessary because it is not possible to pass flags to the script |
| 36 # handler. | 38 # handler. |
| 37 DEFAULT_BRANCH = 'local' | 39 DEFAULT_BRANCH = 'local' |
| 38 | 40 |
| 39 # Global cache of instances because the Server is recreated for every request. | 41 # Global cache of instances because the Server is recreated for every request. |
| 40 SERVER_INSTANCES = {} | 42 SERVER_INSTANCES = {} |
| 41 | 43 |
| 42 class Server(webapp.RequestHandler): | 44 class Server(webapp.RequestHandler): |
| 43 def _GetInstanceForBranch(self, branch): | 45 def _GetInstanceForBranch(self, branch): |
| 44 if branch in SERVER_INSTANCES: | 46 if branch in SERVER_INSTANCES: |
| 45 return SERVER_INSTANCES[branch] | 47 return SERVER_INSTANCES[branch] |
| 46 if branch == 'local': | 48 if branch == 'local': |
| 47 fetcher = LocalFetcher(EXTENSIONS_PATH) | 49 fetcher = LocalFetcher(EXTENSIONS_PATH) |
| 48 # No cache for local doc server. | 50 # No cache for local doc server. |
| 49 cache_timeout_seconds = 0 | 51 cache_timeout_seconds = 0 |
| 50 else: | 52 else: |
| 51 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) | 53 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) |
| 52 cache_timeout_seconds = 300 | 54 cache_timeout_seconds = 300 |
| 53 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) | 55 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) |
| 54 api_data_source = APIDataSource(cache_builder, API_PATH) | 56 api_data_source = APIDataSource(cache_builder, API_PATH) |
| 57 intro_data_source = IntroDataSource(cache_builder, INTRO_PATH) |
| 55 template_data_source = TemplateDataSource( | 58 template_data_source = TemplateDataSource( |
| 56 branch, | 59 branch, |
| 57 api_data_source, | 60 api_data_source, |
| 61 intro_data_source, |
| 58 cache_builder, | 62 cache_builder, |
| 59 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) | 63 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) |
| 60 SERVER_INSTANCES[branch] = ServerInstance( | 64 SERVER_INSTANCES[branch] = ServerInstance( |
| 61 template_data_source, | 65 template_data_source, |
| 62 cache_builder) | 66 cache_builder) |
| 63 return SERVER_INSTANCES[branch] | 67 return SERVER_INSTANCES[branch] |
| 64 | 68 |
| 65 def _HandleRequest(self, path): | 69 def _HandleRequest(self, path): |
| 66 channel_name, real_path = ( | 70 channel_name, real_path = ( |
| 67 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH)) | 71 branch_utility.SplitChannelNameFromPath(path, default=DEFAULT_BRANCH)) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 | 87 |
| 84 def main(): | 88 def main(): |
| 85 handlers = [ | 89 handlers = [ |
| 86 ('/.*', Server), | 90 ('/.*', Server), |
| 87 ] | 91 ] |
| 88 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) | 92 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) |
| 89 | 93 |
| 90 | 94 |
| 91 if __name__ == '__main__': | 95 if __name__ == '__main__': |
| 92 main() | 96 main() |
| OLD | NEW |