OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import logging | |
7 import urlfetch | |
8 | |
9 from google.appengine.ext import webapp | |
10 from google.appengine.ext.webapp.util import run_wsgi_app | |
11 from branch_utility import BranchUtility | |
12 from resource_fetcher import SubversionFetcher | |
13 | |
14 EXTENSIONS_PATH = 'src/chrome/common/extensions/docs/' | |
15 | |
16 | |
17 class MainPage(webapp.RequestHandler): | |
18 def get(self): | |
19 path = self.request.path.replace('/chrome/extensions/', '') | |
20 | |
21 parts = path.split('/') | |
22 if len(parts) > 1: | |
23 filename = parts[1] | |
24 else: | |
25 filename = parts[0] | |
26 | |
27 if len(path) > 0 and path[0] == '/': | |
28 path = path.strip('/') | |
29 | |
30 fetcher = SubversionFetcher(urlfetch) | |
31 b_util = BranchUtility(urlfetch) | |
32 channel_name = b_util.GetChannelNameFromPath(path) | |
33 branch = b_util.GetBranchNumberForChannelName(channel_name) | |
34 | |
35 logging.info(channel_name + ' ' + branch) | |
36 try: | |
37 result = fetcher.FetchResource(branch, EXTENSIONS_PATH + path) | |
38 content = result.content | |
39 for key in result.headers: | |
40 self.response.headers[key] = result.headers[key] | |
41 except: | |
42 content = 'File not found.' | |
cduvall
2012/05/24 03:06:00
We can catch bad urls even from src.chromium.org.
Aaron Boodman
2012/05/24 06:10:23
Ah, it was directories I was thinking of. We can't
| |
43 | |
44 self.response.out.write(content) | |
45 | |
46 application = webapp.WSGIApplication([ | |
47 ('/.*', MainPage), | |
48 ], debug=False) | |
49 | |
50 | |
51 def main(): | |
52 run_wsgi_app(application) | |
53 | |
54 | |
55 if __name__ == '__main__': | |
56 main() | |
OLD | NEW |