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