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 | 9 |
10 | 10 |
11 BUILD_DIRECTORY = 'out' | 11 BUILD_DIRECTORY = 'out' |
12 CONFIG_DIRECTORY = 'Debug' | 12 CONFIG_DIRECTORY = 'Debug' |
13 SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, | 13 SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, |
14 os.pardir)) | 14 os.pardir)) |
15 SKY_ROOT = os.path.join(SRC_ROOT, 'sky') | 15 SKY_ROOT = os.path.join(SRC_ROOT, 'sky') |
16 GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen') | 16 GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen') |
17 | 17 |
18 | 18 |
19 # FIXME: This doesn't yet support directory listings. We'll do something like: | 19 # FIXME: This doesn't yet support directory listings. We'll do something like: |
20 # http://tools.cherrypy.org/wiki/staticdirindex | 20 # http://tools.cherrypy.org/wiki/staticdirindex |
21 # but have it spit .sky instead of HTML | 21 # but have it spit .sky instead of HTML |
22 | 22 |
23 def main(): | 23 def main(): |
24 parser = argparse.ArgumentParser(description='Sky development server') | 24 parser = argparse.ArgumentParser(description='Sky development server') |
| 25 parser.add_argument('-v', '--verbose', action='store_true', |
| 26 help='Enable logging to the console.') |
25 parser.add_argument('app_path', type=str) | 27 parser.add_argument('app_path', type=str) |
26 parser.add_argument('port', type=int) | 28 parser.add_argument('port', type=int) |
27 args = parser.parse_args() | 29 args = parser.parse_args() |
28 | 30 |
| 31 log_dir = os.path.abspath(os.getcwd()) |
| 32 print "%s logging to access_log.txt in %s" % ( |
| 33 parser.prog, log_dir) |
| 34 |
29 config = { | 35 config = { |
30 'global': { | 36 'global': { |
31 'server.socket_port': args.port, | 37 'server.socket_port': args.port, |
| 38 'log.screen': args.verbose, |
| 39 'log.access_log': os.path.join(log_dir, 'access_log.txt'), |
| 40 # This causes some strange python exception?? |
| 41 # 'log.error_log': os.path.join(log_dir, 'error_log.txt'), |
32 }, | 42 }, |
33 '/': { | 43 '/': { |
34 'tools.staticdir.on': True, | 44 'tools.staticdir.on': True, |
35 'tools.staticdir.dir': os.path.abspath(args.app_path), | 45 'tools.staticdir.dir': os.path.abspath(args.app_path), |
36 }, | 46 }, |
37 '/mojo': { | 47 '/mojo': { |
38 'tools.staticdir.on': True, | 48 'tools.staticdir.on': True, |
39 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'mojo'), | 49 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'mojo'), |
40 }, | 50 }, |
41 '/sky': { | 51 '/sky': { |
42 'tools.staticdir.on': True, | 52 'tools.staticdir.on': True, |
43 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky'), | 53 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky'), |
44 }, | 54 }, |
45 '/sky/framework': { | 55 '/sky/framework': { |
46 'tools.staticdir.on': True, | 56 'tools.staticdir.on': True, |
47 'tools.staticdir.dir': | 57 'tools.staticdir.dir': |
48 os.path.join(SKY_ROOT, 'framework'), | 58 os.path.join(SKY_ROOT, 'framework'), |
49 }, | 59 }, |
50 } | 60 } |
51 cherrypy.quickstart(config=config) | 61 cherrypy.quickstart(config=config) |
52 | 62 |
53 | 63 |
54 if __name__ == '__main__': | 64 if __name__ == '__main__': |
55 main() | 65 main() |
OLD | NEW |