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

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

Issue 10828221: Revert "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 | « chrome/common/extensions/docs/server/app.yaml ('k') | 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 # TODO(aa): Remove once we have a homepage for developer.chrome.com. 148 # TODO(aa): Remove once we have a homepage for developer.chrome.com.
149 if (self.path == [] and 149 if (self.path == [] and
150 self.request.url.startswith('http://developer.chrome.com')): 150 self.request.url.startswith('http://developer.chrome.com')):
151 self.redirect('http://developers.google.com/chrome') 151 self.redirect('http://developers.google.com/chrome')
152 return False 152 return False
153 153
154 return self.redirectToIndexIfNecessary() 154 return self.redirectToIndexIfNecessary()
155 155
156 156
157 def stripPathPrefix(self):
158 # Remove chrome prefix if present. This happens in the case of
159 # http://code.google.com/chrome/extensions/...
160 if self.path[0:2] == ['chrome', 'extensions']:
161 self.path = self.path[2:]
162 return self.redirectToIndexIfNecessary()
163
164
165 def initChannel(self): 157 def initChannel(self):
166 self.channel = GetChannelByName(self.path[0]) 158 self.channel = GetChannelByName(self.path[0])
167 if self.channel is not None: 159 if self.channel is not None:
168 self.path.pop(0) 160 self.path.pop(0)
169 else: 161 else:
170 self.channel = Channel.DEFAULT 162 self.channel = Channel.DEFAULT
171 return self.redirectToIndexIfNecessary() 163 return self.redirectToIndexIfNecessary()
172 164
173 165
174 def initDocFamily(self): 166 def initDocFamily(self):
175 if self.path[0] in ('extensions', 'apps'): 167 if self.path[0] in ('extensions', 'apps'):
176 self.docFamily = self.path[0] 168 self.docFamily = self.path.pop(0)
177 self.path.pop(0)
178 else: 169 else:
179 self.docFamily = 'extensions' 170 self.docFamily = 'extensions'
180 return self.redirectToIndexIfNecessary() 171 return self.redirectToIndexIfNecessary()
181 172
182 173
174 def redirectDomain(self):
175 if (self.request.url.startswith('http://code.google.com')):
176 self.path.pop(0) # 'chrome'
177 for channel in ['dev', 'beta', 'stable', 'trunk']:
178 if channel in self.path:
179 position = self.path.index(channel)
180 self.path.pop(position)
181 self.path.insert(0, channel)
182 self.redirect(CHROME_DOMAIN_URL + '/' + '/'.join(self.path), True)
183 return False
184 else:
185 return True
186
187
183 def fetchContent(self): 188 def fetchContent(self):
184 logging.info("fetching: %s" % str((self.branch, self.docFamily, self.path))) 189 logging.info("fetching: %s" % str((self.branch, self.docFamily, self.path)))
185 190
186 # For extensions, try the old directory layout first. 191 # For extensions, try the old directory layout first.
187 result = None 192 result = None
188 oldUrl = '' 193 oldUrl = ''
189 194
190 if self.docFamily == 'extensions': 195 if self.docFamily == 'extensions':
191 oldUrl = GetSrcUrl(self.branch, None, self.path) 196 oldUrl = GetSrcUrl(self.branch, None, self.path)
192 result = urlfetch.fetch(oldUrl) 197 result = urlfetch.fetch(oldUrl)
(...skipping 10 matching lines...) Expand all
203 if (self.path[0] == 'examples' and 208 if (self.path[0] == 'examples' and
204 not (result.headers['content-type'].startswith('image/') or 209 not (result.headers['content-type'].startswith('image/') or
205 result.headers['Content-Type'].startswith('image/'))): 210 result.headers['Content-Type'].startswith('image/'))):
206 result.headers['content-type'] = 'text/plain' 211 result.headers['content-type'] = 'text/plain'
207 212
208 return result 213 return result
209 214
210 215
211 def get(self): 216 def get(self):
212 if (not self.initPath() or 217 if (not self.initPath() or
213 not self.stripPathPrefix() or 218 not self.redirectDomain() or
214 not self.initChannel() or 219 not self.initChannel() or
215 not self.initDocFamily()): 220 not self.initDocFamily()):
216 return 221 return
217 222
218 cacheKey = str((self.channel.name, self.docFamily, self.path)) 223 cacheKey = str((self.channel.name, self.docFamily, self.path))
219 result = memcache.get(cacheKey) 224 result = memcache.get(cacheKey)
220 if result is None: 225 if result is None:
221 logging.info("cache miss: " + cacheKey) 226 logging.info("cache miss: " + cacheKey)
222 227
223 self.branch = None 228 self.branch = None
(...skipping 14 matching lines...) Expand all
238 ('/.*', MainPage), 243 ('/.*', MainPage),
239 ], debug=False) 244 ], debug=False)
240 245
241 246
242 def main(): 247 def main():
243 run_wsgi_app(application) 248 run_wsgi_app(application)
244 249
245 250
246 if __name__ == '__main__': 251 if __name__ == '__main__':
247 main() 252 main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server/app.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698