OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 argparse | 6 import argparse |
7 import os | 7 import os |
8 import cherrypy | 8 import cherrypy |
9 import staticdirindex | |
9 | 10 |
10 | 11 |
11 BUILD_DIRECTORY = 'out' | 12 BUILD_DIRECTORY = 'out' |
12 CONFIG_DIRECTORY = 'Debug' | 13 CONFIG_DIRECTORY = 'Debug' |
13 SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, | 14 SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, |
14 os.pardir)) | 15 os.pardir)) |
15 SKY_ROOT = os.path.join(SRC_ROOT, 'sky') | 16 SKY_ROOT = os.path.join(SRC_ROOT, 'sky') |
16 GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen') | 17 GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen') |
17 | 18 |
18 | 19 |
20 # FIXME: This should be replaced by just json and inflated into DOM client-side. | |
21 def skydir(section="", dir="", path="", **kwargs): | |
22 url = "%s%s" % (cherrypy.request.headers.get('Host', ''), | |
23 cherrypy.request.path_info) | |
24 sky = "<listing>" | |
25 sky += "<style>a { display: block; }" | |
26 sky += "header { border-bottom: 1px solid lightgrey }</style>" | |
27 sky += '<header>Listing for: <a href="' + url + '">' + url +'</a></header>' | |
28 for _, dir_names, file_names in os.walk(path.rstrip(r"\/")): | |
29 for dir_name in sorted(dir_names): | |
30 sky += "<a href=\"%s/\">%s/</a>\n" % (dir_name, dir_name) | |
31 | |
32 del dir_names[:] # limit to one level | |
33 | |
34 for file_name in sorted(file_names): | |
35 sky += "<a href=\"%s\">%s</a>\n" % (file_name, file_name) | |
36 return sky + "</listing>" | |
abarth-chromium
2014/10/31 02:21:37
So much the XSS
| |
37 | |
38 | |
19 # FIXME: This doesn't yet support directory listings. We'll do something like: | 39 # FIXME: This doesn't yet support directory listings. We'll do something like: |
20 # http://tools.cherrypy.org/wiki/staticdirindex | 40 # http://tools.cherrypy.org/wiki/staticdirindex |
21 # but have it spit .sky instead of HTML | 41 # but have it spit .sky instead of HTML |
22 | 42 |
23 def main(): | 43 def main(): |
24 parser = argparse.ArgumentParser(description='Sky development server') | 44 parser = argparse.ArgumentParser(description='Sky development server') |
25 parser.add_argument('-v', '--verbose', action='store_true', | 45 parser.add_argument('-v', '--verbose', action='store_true', |
26 help='Enable logging to the console.') | 46 help='Enable logging to the console.') |
27 parser.add_argument('app_path', type=str) | 47 parser.add_argument('app_path', type=str) |
28 parser.add_argument('port', type=int) | 48 parser.add_argument('port', type=int) |
29 args = parser.parse_args() | 49 args = parser.parse_args() |
30 | 50 |
31 log_dir = os.path.abspath(os.getcwd()) | 51 log_dir = os.path.abspath(os.getcwd()) |
32 print "%s logging to access_log.txt in %s" % ( | 52 print "%s logging to access_log.txt in %s" % ( |
33 parser.prog, log_dir) | 53 parser.prog, log_dir) |
34 | 54 |
35 config = { | 55 config = { |
36 'global': { | 56 'global': { |
37 'server.socket_port': args.port, | 57 'server.socket_port': args.port, |
38 'log.screen': args.verbose, | 58 'log.screen': args.verbose, |
39 'log.access_log': os.path.join(log_dir, 'access_log.txt'), | 59 'log.access_log': os.path.join(log_dir, 'access_log.txt'), |
40 # This causes some strange python exception?? | 60 # This causes some strange python exception?? |
41 # 'log.error_log': os.path.join(log_dir, 'error_log.txt'), | 61 # 'log.error_log': os.path.join(log_dir, 'error_log.txt'), |
42 }, | 62 }, |
43 '/': { | 63 '/': { |
44 'tools.staticdir.on': True, | 64 'tools.staticdir.on': True, |
45 'tools.staticdir.dir': os.path.abspath(args.app_path), | 65 'tools.staticdir.dir': os.path.abspath(args.app_path), |
66 'tools.staticdir.indexlister': skydir, | |
46 }, | 67 }, |
47 '/mojo': { | 68 '/mojo': { |
48 'tools.staticdir.on': True, | 69 'tools.staticdir.on': True, |
49 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'mojo'), | 70 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'mojo'), |
50 }, | 71 }, |
51 '/sky': { | 72 '/sky': { |
52 'tools.staticdir.on': True, | 73 'tools.staticdir.on': True, |
53 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky'), | 74 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky'), |
54 }, | 75 }, |
55 '/sky/framework': { | 76 '/sky/framework': { |
56 'tools.staticdir.on': True, | 77 'tools.staticdir.on': True, |
57 'tools.staticdir.dir': | 78 'tools.staticdir.dir': |
58 os.path.join(SKY_ROOT, 'framework'), | 79 os.path.join(SKY_ROOT, 'framework'), |
59 }, | 80 }, |
60 } | 81 } |
61 cherrypy.quickstart(config=config) | 82 cherrypy.quickstart(config=config) |
62 | 83 |
63 | 84 |
64 if __name__ == '__main__': | 85 if __name__ == '__main__': |
65 main() | 86 main() |
OLD | NEW |