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

Side by Side Diff: chrome/common/extensions/docs/server/main.py

Issue 10821126: adding redirect from codesite to chrome domain (bug 138776) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 cgi 6 import cgi
7 import logging 7 import logging
8 import os 8 import os
9 import re 9 import re
10 10
11 from google.appengine.ext import webapp 11 from google.appengine.ext import webapp
12 from google.appengine.ext.webapp.util import run_wsgi_app 12 from google.appengine.ext.webapp.util import run_wsgi_app
13 from google.appengine.api import memcache 13 from google.appengine.api import memcache
14 from google.appengine.api import urlfetch 14 from google.appengine.api import urlfetch
15 15
16 import app_known_issues 16 import app_known_issues
17 17
18 DEFAULT_CACHE_TIME = 300 18 DEFAULT_CACHE_TIME = 300
19 VIEW_VC_ROOT = 'http://src.chromium.org' 19 VIEW_VC_ROOT = 'http://src.chromium.org'
20 20 CHROME_DOMAIN_URL = 'http://developer.chrome.com'
21 21
22 class Channel(): 22 class Channel():
23 def __init__(self, name, tag): 23 def __init__(self, name, tag):
24 self.name = name 24 self.name = name
25 self.tag = tag 25 self.tag = tag
26 26
27 Channel.DEV = Channel("dev", "2.0-dev") 27 Channel.DEV = Channel("dev", "2.0-dev")
28 Channel.BETA = Channel("beta", "1.1-beta") 28 Channel.BETA = Channel("beta", "1.1-beta")
29 Channel.STABLE = Channel("stable", "") 29 Channel.STABLE = Channel("stable", "")
30 Channel.TRUNK = Channel("trunk", "") 30 Channel.TRUNK = Channel("trunk", "")
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 def initDocFamily(self): 174 def initDocFamily(self):
175 if self.path[0] in ('extensions', 'apps'): 175 if self.path[0] in ('extensions', 'apps'):
176 self.docFamily = self.path[0] 176 self.docFamily = self.path[0]
177 self.path.pop(0) 177 self.path.pop(0)
178 else: 178 else:
179 self.docFamily = 'extensions' 179 self.docFamily = 'extensions'
180 return self.redirectToIndexIfNecessary() 180 return self.redirectToIndexIfNecessary()
181 181
182 182
183 def redirectDomain(self):
184 if (self.request.url.startswith('http://code.google.com')):
185 for channel in ['dev', 'beta', 'stable', 'trunk']:
186 if channel in self.path:
187 position = self.path.index(channel)
188 self.path.pop(position)
189 self.path.insert(0, '')
Aaron Boodman 2012/08/01 09:58:54 This is a little magical. Instead of adding the em
190 self.path.insert(1, channel)
191 self.redirect(CHROME_DOMAIN_URL + '/'.join(self.path))
192 return False
193
194
183 def fetchContent(self): 195 def fetchContent(self):
184 logging.info("fetching: %s" % str((self.branch, self.docFamily, self.path))) 196 logging.info("fetching: %s" % str((self.branch, self.docFamily, self.path)))
185 197
186 # For extensions, try the old directory layout first. 198 # For extensions, try the old directory layout first.
187 result = None 199 result = None
188 oldUrl = '' 200 oldUrl = ''
189 201
190 if self.docFamily == 'extensions': 202 if self.docFamily == 'extensions':
191 oldUrl = GetSrcUrl(self.branch, None, self.path) 203 oldUrl = GetSrcUrl(self.branch, None, self.path)
192 result = urlfetch.fetch(oldUrl) 204 result = urlfetch.fetch(oldUrl)
(...skipping 12 matching lines...) Expand all
205 result.headers['Content-Type'].startswith('image/'))): 217 result.headers['Content-Type'].startswith('image/'))):
206 result.headers['content-type'] = 'text/plain' 218 result.headers['content-type'] = 'text/plain'
207 219
208 return result 220 return result
209 221
210 222
211 def get(self): 223 def get(self):
212 if (not self.initPath() or 224 if (not self.initPath() or
213 not self.stripPathPrefix() or 225 not self.stripPathPrefix() or
214 not self.initChannel() or 226 not self.initChannel() or
215 not self.initDocFamily()): 227 not self.initDocFamily() or
228 not self.redirectDomain()):
216 return 229 return
217 230
218 cacheKey = str((self.channel.name, self.docFamily, self.path)) 231 cacheKey = str((self.channel.name, self.docFamily, self.path))
219 result = memcache.get(cacheKey) 232 result = memcache.get(cacheKey)
220 if result is None: 233 if result is None:
221 logging.info("cache miss: " + cacheKey) 234 logging.info("cache miss: " + cacheKey)
222 235
223 self.branch = None 236 self.branch = None
224 if self.channel is not Channel.TRUNK: 237 if self.channel is not Channel.TRUNK:
225 self.branch = GetBranch(self.channel) 238 self.branch = GetBranch(self.channel)
(...skipping 12 matching lines...) Expand all
238 ('/.*', MainPage), 251 ('/.*', MainPage),
239 ], debug=False) 252 ], debug=False)
240 253
241 254
242 def main(): 255 def main():
243 run_wsgi_app(application) 256 run_wsgi_app(application)
244 257
245 258
246 if __name__ == '__main__': 259 if __name__ == '__main__':
247 main() 260 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698