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

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

Issue 10830206: Revert 149811 - 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 CHROME_DOMAIN_URL = 'http://developer.chrome.com' 20
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, channel)
190 self.redirect(CHROME_DOMAIN_URL + '/' + '/'.join(self.path), True)
191 return False
192
193
194 def fetchContent(self): 183 def fetchContent(self):
195 logging.info("fetching: %s" % str((self.branch, self.docFamily, self.path))) 184 logging.info("fetching: %s" % str((self.branch, self.docFamily, self.path)))
196 185
197 # For extensions, try the old directory layout first. 186 # For extensions, try the old directory layout first.
198 result = None 187 result = None
199 oldUrl = '' 188 oldUrl = ''
200 189
201 if self.docFamily == 'extensions': 190 if self.docFamily == 'extensions':
202 oldUrl = GetSrcUrl(self.branch, None, self.path) 191 oldUrl = GetSrcUrl(self.branch, None, self.path)
203 result = urlfetch.fetch(oldUrl) 192 result = urlfetch.fetch(oldUrl)
(...skipping 12 matching lines...) Expand all
216 result.headers['Content-Type'].startswith('image/'))): 205 result.headers['Content-Type'].startswith('image/'))):
217 result.headers['content-type'] = 'text/plain' 206 result.headers['content-type'] = 'text/plain'
218 207
219 return result 208 return result
220 209
221 210
222 def get(self): 211 def get(self):
223 if (not self.initPath() or 212 if (not self.initPath() or
224 not self.stripPathPrefix() or 213 not self.stripPathPrefix() or
225 not self.initChannel() or 214 not self.initChannel() or
226 not self.initDocFamily() or 215 not self.initDocFamily()):
227 not self.redirectDomain()):
228 return 216 return
229 217
230 cacheKey = str((self.channel.name, self.docFamily, self.path)) 218 cacheKey = str((self.channel.name, self.docFamily, self.path))
231 result = memcache.get(cacheKey) 219 result = memcache.get(cacheKey)
232 if result is None: 220 if result is None:
233 logging.info("cache miss: " + cacheKey) 221 logging.info("cache miss: " + cacheKey)
234 222
235 self.branch = None 223 self.branch = None
236 if self.channel is not Channel.TRUNK: 224 if self.channel is not Channel.TRUNK:
237 self.branch = GetBranch(self.channel) 225 self.branch = GetBranch(self.channel)
(...skipping 12 matching lines...) Expand all
250 ('/.*', MainPage), 238 ('/.*', MainPage),
251 ], debug=False) 239 ], debug=False)
252 240
253 241
254 def main(): 242 def main():
255 run_wsgi_app(application) 243 run_wsgi_app(application)
256 244
257 245
258 if __name__ == '__main__': 246 if __name__ == '__main__':
259 main() 247 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