mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Previously we were using string concatenation to build up the directory listing. Now we fetch some JSON from the server and use data binding to inflate a directory listing. This exmaple doesn't work yet because we're missing support for template@repeat, but hopefully we'll get that soon. Also, added support for setRequestHeader to XMLHttpRequest. R=rafaelw@chromium.org Review URL: https://codereview.chromium.org/688413005
81 lines
2.6 KiB
Python
Executable File
81 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# Copyright 2014 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import argparse
|
|
import cherrypy
|
|
import json
|
|
import os
|
|
import staticdirindex
|
|
|
|
|
|
BUILD_DIRECTORY = 'out'
|
|
CONFIG_DIRECTORY = 'Debug'
|
|
SRC_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir,
|
|
os.pardir))
|
|
SKY_ROOT = os.path.join(SRC_ROOT, 'sky')
|
|
GEN_ROOT = os.path.join(SRC_ROOT, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'gen')
|
|
|
|
|
|
def skydir(section="", dir="", path="", **kwargs):
|
|
if cherrypy.request.params.get('format') is None:
|
|
return '<sky><import src="/sky/examples/file-browser.sky"/><file-browser/></sky>'
|
|
result = dict()
|
|
result['directories'] = []
|
|
result['files'] = []
|
|
for _, dir_names, file_names in os.walk(path.rstrip(r"\/")):
|
|
for dir_name in sorted(dir_names):
|
|
result["directories"].append(dir_name)
|
|
|
|
del dir_names[:] # limit to one level
|
|
|
|
for file_name in sorted(file_names):
|
|
result["files"].append(file_name)
|
|
return json.dumps(result)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='Sky development server')
|
|
parser.add_argument('-v', '--verbose', action='store_true',
|
|
help='Enable logging to the console.')
|
|
parser.add_argument('app_path', type=str)
|
|
parser.add_argument('port', type=int)
|
|
args = parser.parse_args()
|
|
|
|
log_dir = os.path.abspath(os.getcwd())
|
|
print "%s logging to access_log.txt in %s" % (
|
|
parser.prog, log_dir)
|
|
|
|
config = {
|
|
'global': {
|
|
'server.socket_port': args.port,
|
|
'log.screen': args.verbose,
|
|
'log.access_log': os.path.join(log_dir, 'access_log.txt'),
|
|
# This causes some strange python exception??
|
|
# 'log.error_log': os.path.join(log_dir, 'error_log.txt'),
|
|
},
|
|
'/': {
|
|
'tools.staticdir.on': True,
|
|
'tools.staticdir.dir': os.path.abspath(args.app_path),
|
|
'tools.staticdir.indexlister': skydir,
|
|
},
|
|
'/mojo/public': {
|
|
'tools.staticdir.on': True,
|
|
'tools.staticdir.dir': os.path.join(GEN_ROOT, 'mojo', 'public'),
|
|
},
|
|
'/mojo/services': {
|
|
'tools.staticdir.on': True,
|
|
'tools.staticdir.dir': os.path.join(GEN_ROOT, 'mojo', 'services'),
|
|
},
|
|
'/sky/services': {
|
|
'tools.staticdir.on': True,
|
|
'tools.staticdir.dir': os.path.join(GEN_ROOT, 'sky', 'services'),
|
|
},
|
|
}
|
|
cherrypy.quickstart(config=config)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|