Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: chrome/common/extensions/docs/server2/handler.py

Issue 10895027: Extension Docs Server 2: Redirect code.google.com/chrome/extensions to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import logging 5 import logging
6 import os 6 import os
7 from StringIO import StringIO 7 from StringIO import StringIO
8 import sys 8 import sys
9 9
10 from appengine_wrappers import webapp 10 from appengine_wrappers import webapp
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 self.out = StringIO() 137 self.out = StringIO()
138 self.headers = {} 138 self.headers = {}
139 139
140 def set_status(self, status): 140 def set_status(self, status):
141 self.status = status 141 self.status = status
142 142
143 class _MockRequest(object): 143 class _MockRequest(object):
144 def __init__(self, path): 144 def __init__(self, path):
145 self.headers = {} 145 self.headers = {}
146 self.path = path 146 self.path = path
147 self.url = 'http://localhost' + path
147 148
148 class Handler(webapp.RequestHandler): 149 class Handler(webapp.RequestHandler):
149 def __init__(self, request, response, local_path=EXTENSIONS_PATH): 150 def __init__(self, request, response, local_path=EXTENSIONS_PATH):
150 self._local_path = local_path 151 self._local_path = local_path
151 super(Handler, self).__init__(request, response) 152 super(Handler, self).__init__(request, response)
152 153
153 def _HandleGet(self, path): 154 def _HandleGet(self, path):
154 channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path) 155 channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path)
155 # TODO: Detect that these are directories and serve index.html out of them. 156 # TODO: Detect that these are directories and serve index.html out of them.
156 if real_path.strip('/') == 'apps': 157 if real_path.strip('/') == 'apps':
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 # If |needs_render| was True, this page was already rendered, and we don't 221 # If |needs_render| was True, this page was already rendered, and we don't
221 # need to render again. 222 # need to render again.
222 github_invalidation_cache = GITHUB_COMPILED_FILE_SYSTEM.Create( 223 github_invalidation_cache = GITHUB_COMPILED_FILE_SYSTEM.Create(
223 lambda _: needs_render.Set(True), 224 lambda _: needs_render.Set(True),
224 compiled_fs.CRON_GITHUB_INVALIDATION) 225 compiled_fs.CRON_GITHUB_INVALIDATION)
225 if needs_render.Get(): 226 if needs_render.Get():
226 self._Render([PUBLIC_TEMPLATE_PATH + '/apps/samples.html'], channel) 227 self._Render([PUBLIC_TEMPLATE_PATH + '/apps/samples.html'], channel)
227 228
228 self.response.out.write('Success') 229 self.response.out.write('Success')
229 230
231
not at google - send to devlin 2012/08/29 07:20:46 nits: surrounding this method in 2 blank lines on
Aaron Boodman 2012/08/29 19:42:42 Done.
232 def _RedirectFromCodeDotGoogleDotCom(self, path):
233 if (not self.request.url.startswith(('http://code.google.com',
234 'https://code.google.com'))):
235 return False
236
237 newUrl = 'http://developer.chrome.com/'
238
239 # switch to https if necessary
240 if (self.request.url.startswith('https')):
241 newUrl = newUrl.replace('http', 'https', 1)
242
243 path = path.split('/')
244 if len(path) > 0 and path[0] == 'chrome':
245 path.pop(0)
246 for channel in ['dev', 'beta', 'stable', 'trunk']:
not at google - send to devlin 2012/08/29 07:20:46 I've been trying to keep knowledge of the branches
Aaron Boodman 2012/08/29 19:42:42 Done.
247 if channel in path:
248 position = path.index(channel)
249 path.pop(position)
250 path.insert(0, channel)
251 newUrl += '/'.join(path)
252 self.redirect(newUrl)
253 return True
254
255
230 def get(self): 256 def get(self):
231 path = self.request.path 257 path = self.request.path
232 if path.startswith('/cron'): 258 if path.startswith('/cron'):
233 self._HandleCron(path) 259 self._HandleCron(path)
234 else: 260 return
235 # Redirect paths like "directory" to "directory/". This is so relative 261
236 # file paths will know to treat this as a directory. 262 # Redirect paths like "directory" to "directory/". This is so relative
237 if os.path.splitext(path)[1] == '' and path[-1] != '/': 263 # file paths will know to treat this as a directory.
238 self.redirect(path + '/') 264 if os.path.splitext(path)[1] == '' and path[-1] != '/':
239 path = path.replace('/chrome/', '') 265 self.redirect(path + '/')
240 path = path.strip('/') 266 return
267
268 path = path.strip('/')
269 if not self._RedirectFromCodeDotGoogleDotCom(path):
241 self._HandleGet(path) 270 self._HandleGet(path)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/app.yaml ('k') | chrome/common/extensions/docs/server2/integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698