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

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: Created 8 years, 7 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..f42305e66a3281ccc56f47b6c632c7e1827e5440 100755
--- a/chrome/common/extensions/docs/server2/echo_handler.py
+++ b/chrome/common/extensions/docs/server2/echo_handler.py
@@ -3,21 +3,51 @@
# 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 resource_fetcher import SubversionFetcher, LocalFetcher
+from template_utility import TemplateUtility
+DOCS_PATH = 'chrome/common/extensions/docs/'
Aaron Boodman 2012/06/02 07:50:22 os.path.join() ... all throughout this code.
cduvall 2012/06/02 19:12:05 So these paths can be used as URLs or as file path
Aaron Boodman 2012/06/03 05:43:14 I see. When you use it as a path, can you split by
cduvall 2012/06/04 21:53:25 Done.
+STATIC_PATH = DOCS_PATH + 'static/'
+PUBLIC_TEMPLATE_PATH = DOCS_PATH + 'template2/public/'
+PRIVATE_TEMPLATE_PATH = DOCS_PATH + 'template2/private/'
class MainPage(webapp.RequestHandler):
+ 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.replace('/chrome/extensions/', '')
+ path = self.request.path
+ # Hack for getting local files. Still researching how to use a command line
+ # argument to toggle this.
Aaron Boodman 2012/06/02 07:50:22 They don't show up in sys.argv?
cduvall 2012/06/02 19:12:05 Nope, since dev_appserver.py calls this script sep
+ if path.startswith('/local'):
+ logging.info(path)
+ path = path.replace('/local', '')
+ fetcher = LocalFetcher()
+ else:
+ fetcher = SubversionFetcher(urlfetch)
+ branch_util = BranchUtility(urlfetch)
+ template_util = TemplateUtility()
+
+ path = path.replace('/chrome/extensions/', '')
parts = path.split('/')
if len(parts) > 1:
filename = parts[1]
@@ -27,19 +57,20 @@ class MainPage(webapp.RequestHandler):
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)
+ channel_name = branch_util.GetChannelNameFromPath(path)
+ branch = branch_util.GetBranchNumberForChannelName(channel_name)
- 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]
+ content = self._FetchResource(fetcher, branch,
+ PUBLIC_TEMPLATE_PATH + filename)
+ content = template_util.RenderTemplate('{"test": "Hello"}', content)
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 +78,6 @@ application = webapp.WSGIApplication([
('/.*', MainPage),
], debug=False)
-
def main():
run_wsgi_app(application)

Powered by Google App Engine
This is Rietveld 408576698