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 |
| 8 import json |
7 import os | 9 import os |
8 import cherrypy | |
9 import staticdirindex | 10 import staticdirindex |
10 | 11 |
11 | 12 |
12 BUILD_DIRECTORY = 'out' | 13 BUILD_DIRECTORY = 'out' |
13 CONFIG_DIRECTORY = 'Debug' | 14 CONFIG_DIRECTORY = 'Debug' |
14 SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, | 15 SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, |
15 os.pardir)) | 16 os.pardir)) |
16 SKY_ROOT = os.path.join(SRC_ROOT, 'sky') | 17 SKY_ROOT = os.path.join(SRC_ROOT, 'sky') |
17 GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen') | 18 GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen') |
18 | 19 |
19 | 20 |
20 # FIXME: This should be replaced by just json and inflated into DOM client-side. | |
21 def skydir(section="", dir="", path="", **kwargs): | 21 def skydir(section="", dir="", path="", **kwargs): |
22 url = "%s%s" % (cherrypy.request.headers.get('Host', ''), | 22 if cherrypy.request.params.get('format') is None: |
23 cherrypy.request.path_info) | 23 return '<sky><import src="/sky/examples/file-browser.sky"/><file-browser
/></sky>' |
24 sky = "<listing>" | 24 result = dict() |
25 sky += "<style>a { display: block; }" | 25 result['directories'] = [] |
26 sky += "header { border-bottom: 1px solid lightgrey }</style>" | 26 result['files'] = [] |
27 sky += '<header>Listing for: <a href="' + url + '">' + url +'</a></header>' | |
28 for _, dir_names, file_names in os.walk(path.rstrip(r"\/")): | 27 for _, dir_names, file_names in os.walk(path.rstrip(r"\/")): |
29 for dir_name in sorted(dir_names): | 28 for dir_name in sorted(dir_names): |
30 sky += "<a href=\"%s/\">%s/</a>\n" % (dir_name, dir_name) | 29 result["directories"].append(dir_name) |
31 | 30 |
32 del dir_names[:] # limit to one level | 31 del dir_names[:] # limit to one level |
33 | 32 |
34 for file_name in sorted(file_names): | 33 for file_name in sorted(file_names): |
35 sky += "<a href=\"%s\">%s</a>\n" % (file_name, file_name) | 34 result["files"].append(file_name) |
36 return sky + "</listing>" | 35 return json.dumps(result) |
37 | 36 |
38 | 37 |
39 # FIXME: This doesn't yet support directory listings. We'll do something like: | |
40 # http://tools.cherrypy.org/wiki/staticdirindex | |
41 # but have it spit .sky instead of HTML | |
42 | |
43 def main(): | 38 def main(): |
44 parser = argparse.ArgumentParser(description='Sky development server') | 39 parser = argparse.ArgumentParser(description='Sky development server') |
45 parser.add_argument('-v', '--verbose', action='store_true', | 40 parser.add_argument('-v', '--verbose', action='store_true', |
46 help='Enable logging to the console.') | 41 help='Enable logging to the console.') |
47 parser.add_argument('app_path', type=str) | 42 parser.add_argument('app_path', type=str) |
48 parser.add_argument('port', type=int) | 43 parser.add_argument('port', type=int) |
49 args = parser.parse_args() | 44 args = parser.parse_args() |
50 | 45 |
51 log_dir = os.path.abspath(os.getcwd()) | 46 log_dir = os.path.abspath(os.getcwd()) |
52 print "%s logging to access_log.txt in %s" % ( | 47 print "%s logging to access_log.txt in %s" % ( |
(...skipping 23 matching lines...) Expand all Loading... |
76 '/sky/services': { | 71 '/sky/services': { |
77 'tools.staticdir.on': True, | 72 'tools.staticdir.on': True, |
78 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky', 'services'), | 73 'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky', 'services'), |
79 }, | 74 }, |
80 } | 75 } |
81 cherrypy.quickstart(config=config) | 76 cherrypy.quickstart(config=config) |
82 | 77 |
83 | 78 |
84 if __name__ == '__main__': | 79 if __name__ == '__main__': |
85 main() | 80 main() |
OLD | NEW |