Chromium Code Reviews| 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 logging | 16 import logging |
| 17 import urlfetch | 17 import urlfetch |
| 18 | 18 |
| 19 from google.appengine.ext import webapp | 19 from google.appengine.ext import webapp |
| 20 from google.appengine.ext.webapp.util import run_wsgi_app | 20 from google.appengine.ext.webapp.util import run_wsgi_app |
| 21 | 21 |
| 22 from api_data_source import APIDataSource | |
| 23 from fetcher_cache import FetcherCache | |
| 22 from local_fetcher import LocalFetcher | 24 from local_fetcher import LocalFetcher |
| 23 from server_instance import ServerInstance | 25 from server_instance import ServerInstance |
| 24 from subversion_fetcher import SubversionFetcher | 26 from subversion_fetcher import SubversionFetcher |
| 25 from template_data_source import TemplateDataSource | 27 from template_data_source import TemplateDataSource |
| 26 | 28 |
| 27 EXTENSIONS_PATH = 'chrome/common/extensions/' | 29 EXTENSIONS_PATH = 'chrome/common/extensions' |
| 28 DOCS_PATH = 'docs/' | 30 DOCS_PATH = 'docs' |
| 29 PUBLIC_TEMPLATE_PATH = DOCS_PATH + 'template2/public/' | 31 API_PATH = 'api' |
| 30 PRIVATE_TEMPLATE_PATH = DOCS_PATH + 'template2/private/' | 32 PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/template2/public' |
| 33 PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/template2/private' | |
|
not at google - send to devlin
2012/06/18 19:30:40
these are filesystem paths right? Should be os.pat
cduvall
2012/06/18 19:48:46
These are URLs. When they are used as filesystem p
| |
| 31 | 34 |
| 32 # Global cache of instances because the Server is recreated for every request. | 35 # Global cache of instances because the Server is recreated for every request. |
| 33 SERVER_INSTANCES = {} | 36 SERVER_INSTANCES = {} |
| 34 | 37 |
| 35 class Server(webapp.RequestHandler): | 38 class Server(webapp.RequestHandler): |
| 36 def _GetInstanceForBranch(self, branch): | 39 def _GetInstanceForBranch(self, branch): |
| 37 if branch in SERVER_INSTANCES: | 40 if branch in SERVER_INSTANCES: |
| 38 return SERVER_INSTANCES[branch] | 41 return SERVER_INSTANCES[branch] |
| 39 if branch == 'local': | 42 if branch == 'local': |
| 40 fetcher = LocalFetcher(EXTENSIONS_PATH) | 43 fetcher = LocalFetcher(EXTENSIONS_PATH) |
| 41 # No cache for local doc server. | 44 # No cache for local doc server. |
| 42 cache_timeout_seconds = 0 | 45 cache_timeout_seconds = 0 |
| 43 else: | 46 else: |
| 44 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) | 47 fetcher = SubversionFetcher(branch, EXTENSIONS_PATH, urlfetch) |
| 45 cache_timeout_seconds = 300 | 48 cache_timeout_seconds = 300 |
| 46 data_source = TemplateDataSource( | 49 cache_builder = FetcherCache.Builder(fetcher, cache_timeout_seconds) |
| 47 fetcher, | 50 template_data_source = TemplateDataSource( |
| 48 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH], | 51 cache_builder, |
| 49 cache_timeout_seconds) | 52 [PUBLIC_TEMPLATE_PATH, PRIVATE_TEMPLATE_PATH]) |
| 50 SERVER_INSTANCES[branch] = ServerInstance(data_source, fetcher) | 53 api_data_source = APIDataSource(cache_builder, [API_PATH]) |
| 54 SERVER_INSTANCES[branch] = ServerInstance( | |
| 55 api_data_source, | |
| 56 template_data_source, | |
| 57 fetcher) | |
| 51 return SERVER_INSTANCES[branch] | 58 return SERVER_INSTANCES[branch] |
| 52 | 59 |
| 53 def _HandleRequest(self, path): | 60 def _HandleRequest(self, path): |
| 54 channel_name = branch_utility.GetChannelNameFromPath(path) | 61 channel_name = branch_utility.GetChannelNameFromPath(path) |
| 55 branch = branch_utility.GetBranchNumberForChannelName(channel_name, | 62 branch = branch_utility.GetBranchNumberForChannelName(channel_name, |
| 56 urlfetch) | 63 urlfetch) |
| 57 self._GetInstanceForBranch(branch).Run(path, self) | 64 self._GetInstanceForBranch(branch).Run(path, self) |
| 58 | 65 |
| 59 def get(self): | 66 def get(self): |
| 60 path = self.request.path | 67 path = self.request.path |
| 61 path = path.replace('/chrome/extensions/', '') | 68 path = path.replace('/chrome/extensions/', '') |
| 62 if len(path) > 0 and path[0] == '/': | 69 if len(path) > 0 and path[0] == '/': |
| 63 path = path.strip('/') | 70 path = path.strip('/') |
| 64 self._HandleRequest(path) | 71 self._HandleRequest(path) |
| 65 | 72 |
| 66 def main(): | 73 def main(): |
| 67 handlers = [ | 74 handlers = [ |
| 68 ('/.*', Server), | 75 ('/.*', Server), |
| 69 ] | 76 ] |
| 70 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) | 77 run_wsgi_app(webapp.WSGIApplication(handlers, debug=False)) |
| 71 | 78 |
| 72 | 79 |
| 73 if __name__ == '__main__': | 80 if __name__ == '__main__': |
| 74 main() | 81 main() |
| OLD | NEW |