Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/echo_handler.py |
| diff --git a/chrome/common/extensions/docs/server2/echo_handler.py b/chrome/common/extensions/docs/server2/echo_handler.py |
| index 5dee167ee7b2120d219612ded7b6e12c27d7509e..5fe6d98e4186600ea382521a4cb4136749d15aa1 100755 |
| --- a/chrome/common/extensions/docs/server2/echo_handler.py |
| +++ b/chrome/common/extensions/docs/server2/echo_handler.py |
| @@ -3,43 +3,70 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import sys |
| +import os |
| + |
| +# Add the original server location to sys.path so we are able to import |
| +# modules from there. |
| +SERVER_PATH = 'chrome/common/extensions/docs/server2/' |
| +if os.path.abspath(SERVER_PATH) not in sys.path: |
| + sys.path.append(os.path.abspath(SERVER_PATH)) |
| + |
| import logging |
| import urlfetch |
| from google.appengine.ext import webapp |
| from google.appengine.ext.webapp.util import run_wsgi_app |
| -from branch_utility import BranchUtility |
| -from resource_fetcher import SubversionFetcher |
| -EXTENSIONS_PATH = 'src/chrome/common/extensions/docs/' |
| +from branch_utility import BranchUtility |
| +from local_fetcher import LocalFetcher |
| +from subversion_fetcher import SubversionFetcher |
| +from template_fetcher import TemplateFetcher |
| +from template_utility import TemplateUtility |
| +EXTENSIONS_PATH = 'chrome/common/extensions/' |
| +DOCS_PATH = 'docs/' |
| +STATIC_PATH = DOCS_PATH + 'static/' |
| +PUBLIC_TEMPLATE_PATH = DOCS_PATH + 'template2/public/' |
| +PRIVATE_TEMPLATE_PATH = DOCS_PATH + 'template2/private/' |
| class MainPage(webapp.RequestHandler): |
| - def get(self): |
| - path = self.request.path.replace('/chrome/extensions/', '') |
| + def _FetchResource(self, fetcher, branch, path): |
| + result = fetcher.FetchResource(branch, path) |
| + for key in result.headers: |
| + self.response.headers[key] = result.headers[key] |
| + return result.content |
| + def get(self): |
| + path = self.request.path |
| + path = path.replace('/chrome/extensions/', '') |
| parts = path.split('/') |
| - if len(parts) > 1: |
| - filename = parts[1] |
| - else: |
| - filename = parts[0] |
| + filename = parts[-1] |
| if len(path) > 0 and path[0] == '/': |
| path = path.strip('/') |
| - fetcher = SubversionFetcher(urlfetch) |
| - b_util = BranchUtility(urlfetch) |
| - channel_name = b_util.GetChannelNameFromPath(path) |
| - branch = b_util.GetBranchNumberForChannelName(channel_name) |
| + branch_util = BranchUtility(urlfetch) |
| + channel_name = branch_util.GetChannelNameFromPath(path) |
| + branch = branch_util.GetBranchNumberForChannelName(channel_name) |
| + |
| + if channel_name == 'local': |
| + fetcher = LocalFetcher(EXTENSIONS_PATH) |
| + else: |
| + fetcher = SubversionFetcher(EXTENSIONS_PATH, urlfetch) |
| + template_fetcher = TemplateFetcher(branch, fetcher) |
| + template_util = TemplateUtility() |
| - logging.info(channel_name + ' ' + branch) |
| try: |
| - result = fetcher.FetchResource(branch, EXTENSIONS_PATH + filename) |
| - content = result.content |
| - for key in result.headers: |
| - self.response.headers[key] = result.headers[key] |
| + template = template_fetcher[PUBLIC_TEMPLATE_PATH + filename] |
|
Aaron Boodman
2012/06/05 00:50:04
Like kalman suggested, I think this should return
|
| + content = template_util.RenderTemplate(template, '{"test": "Hello"}') |
| except: |
| - content = 'File not found.' |
| + logging.info('Template for %s not found.' % filename) |
| + |
| + try: |
| + content = self._FetchResource(fetcher, branch, STATIC_PATH + filename) |
| + except: |
| + content = 'File not found.' |
| self.response.out.write(content) |
| @@ -47,7 +74,6 @@ application = webapp.WSGIApplication([ |
| ('/.*', MainPage), |
| ], debug=False) |
| - |
| def main(): |
| run_wsgi_app(application) |