Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8998)

Unified Diff: chrome/common/extensions/docs/server2/echo_handler.py

Issue 10500004: Die build.py, Die: Part 2 (LocalFetcher, Handlebar support, build script) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: TemplateFetcher now has dictionary interface Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698