| 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 cherrypy | 7 import cherrypy |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import staticdirindex | 10 import staticdirindex |
| 11 import skypy.paths as paths | 11 from skypy.paths import Paths |
| 12 import skypy.configuration as configuration |
| 12 | 13 |
| 13 def skydir(section="", dir="", path="", **kwargs): | 14 def skydir(section="", dir="", path="", **kwargs): |
| 14 if cherrypy.request.params.get('format') is None: | 15 if cherrypy.request.params.get('format') is None: |
| 15 return '<sky><import src="/sky/examples/file-browser.sky"/><file-browser
/></sky>' | 16 return '<sky><import src="/sky/examples/file-browser.sky"/><file-browser
/></sky>' |
| 16 result = dict() | 17 result = dict() |
| 17 result['directories'] = [] | 18 result['directories'] = [] |
| 18 result['files'] = [] | 19 result['files'] = [] |
| 19 for _, dir_names, file_names in os.walk(path.rstrip(r"\/")): | 20 for _, dir_names, file_names in os.walk(path.rstrip(r"\/")): |
| 20 for dir_name in sorted(dir_names): | 21 for dir_name in sorted(dir_names): |
| 21 result["directories"].append(dir_name) | 22 result["directories"].append(dir_name) |
| 22 | 23 |
| 23 del dir_names[:] # limit to one level | 24 del dir_names[:] # limit to one level |
| 24 | 25 |
| 25 for file_name in sorted(file_names): | 26 for file_name in sorted(file_names): |
| 26 result["files"].append(file_name) | 27 result["files"].append(file_name) |
| 27 return json.dumps(result) | 28 return json.dumps(result) |
| 28 | 29 |
| 29 | 30 |
| 30 def main(): | 31 def main(): |
| 31 parser = argparse.ArgumentParser(description='Sky development server') | 32 parser = argparse.ArgumentParser(description='Sky development server') |
| 32 parser.add_argument('-v', '--verbose', action='store_true', | 33 parser.add_argument('-v', '--verbose', action='store_true', |
| 33 help='Enable logging to the console.') | 34 help='Enable logging to the console.') |
| 34 parser.add_argument('app_path', type=str) | 35 parser.add_argument('app_path', type=str) |
| 35 parser.add_argument('port', type=int) | 36 parser.add_argument('port', type=int) |
| 37 configuration.add_arguments(parser) |
| 36 args = parser.parse_args() | 38 args = parser.parse_args() |
| 37 | 39 |
| 38 log_dir = os.path.abspath(os.getcwd()) | 40 log_dir = os.path.abspath(os.getcwd()) |
| 39 | 41 |
| 42 paths = Paths(os.path.join('out', args.configuration)) |
| 43 |
| 40 config = { | 44 config = { |
| 41 'global': { | 45 'global': { |
| 42 'server.socket_port': args.port, | 46 'server.socket_port': args.port, |
| 43 'tools.staticdir.content_types' : { | 47 'tools.staticdir.content_types' : { |
| 44 'sky': 'text/sky', | 48 'sky': 'text/sky', |
| 45 }, | 49 }, |
| 46 'log.screen': args.verbose, | 50 'log.screen': args.verbose, |
| 47 'log.access_log': os.path.join(log_dir, 'access_log.txt'), | 51 'log.access_log': os.path.join(log_dir, 'access_log.txt'), |
| 48 # This causes some strange python exception?? | 52 # This causes some strange python exception?? |
| 49 # 'log.error_log': os.path.join(log_dir, 'error_log.txt'), | 53 # 'log.error_log': os.path.join(log_dir, 'error_log.txt'), |
| 50 }, | 54 }, |
| 51 '/': { | 55 '/': { |
| 52 'tools.staticdir.on': True, | 56 'tools.staticdir.on': True, |
| 53 'tools.staticdir.dir': os.path.abspath(args.app_path), | 57 'tools.staticdir.dir': os.path.abspath(args.app_path), |
| 54 'tools.staticdir.indexlister': skydir, | 58 'tools.staticdir.indexlister': skydir, |
| 55 }, | 59 }, |
| 56 '/mojo/public': { | 60 '/mojo/public': { |
| 57 'tools.staticdir.on': True, | 61 'tools.staticdir.on': True, |
| 58 'tools.staticdir.dir': os.path.join(paths.GEN_ROOT, 'mojo', 'public'
), | 62 'tools.staticdir.dir': os.path.join(paths.gen_root, 'mojo', 'public'
), |
| 59 }, | 63 }, |
| 60 '/mojo/services': { | 64 '/mojo/services': { |
| 61 'tools.staticdir.on': True, | 65 'tools.staticdir.on': True, |
| 62 'tools.staticdir.dir': os.path.join(paths.GEN_ROOT, 'mojo', 'service
s'), | 66 'tools.staticdir.dir': os.path.join(paths.gen_root, 'mojo', 'service
s'), |
| 63 }, | 67 }, |
| 64 '/sky/services': { | 68 '/sky/services': { |
| 65 'tools.staticdir.on': True, | 69 'tools.staticdir.on': True, |
| 66 'tools.staticdir.dir': os.path.join(paths.GEN_ROOT, 'sky', 'services
'), | 70 'tools.staticdir.dir': os.path.join(paths.gen_root, 'sky', 'services
'), |
| 67 }, | 71 }, |
| 68 } | 72 } |
| 69 cherrypy.quickstart(config=config) | 73 cherrypy.quickstart(config=config) |
| 70 | 74 |
| 71 | 75 |
| 72 if __name__ == '__main__': | 76 if __name__ == '__main__': |
| 73 main() | 77 main() |
| OLD | NEW |