Eric Seidel eb07773150 Add a sky_server for running sky apps
This automatically adds /sky and /mojo mappings
to the generated files for each.

Also taught skydb to use this new server.

R=esprehn@chromium.org, abarth@chromium.org

Review URL: https://codereview.chromium.org/682153003
2014-10-28 12:42:53 -07:00

70 lines
2.0 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 os
import subprocess
import sys
import urlparse
BUILD_DIRECTORY = 'out'
CONFIG_DIRECTORY = 'Debug'
SKY_TOOLS_DIRECTORY = os.path.abspath(os.path.join(__file__, os.pardir))
MOJO_SHELL_PATH = os.path.abspath(os.path.join(SKY_TOOLS_DIRECTORY, os.pardir,
os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell'))
SUPPORTED_MIME_TYPES = [
'text/html',
'text/sky',
'text/plain',
]
def start_http_server_for_file(path):
HTTP_PORT = 9999
server_command = [
os.path.join(SKY_TOOLS_DIRECTORY, 'sky_server'),
os.path.dirname(os.path.abspath(path)),
str(HTTP_PORT),
]
subprocess.Popen(server_command)
return 'http://localhost:%s/%s' % (HTTP_PORT, os.path.basename(path))
def main():
parser = argparse.ArgumentParser(description='Sky launcher/debugger')
parser.add_argument('--gdb', action='store_true')
parser.add_argument('url', nargs='?', type=str)
args = parser.parse_args()
content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/')
for mime_type in SUPPORTED_MIME_TYPES]
shell_command = [
MOJO_SHELL_PATH,
'--v=1',
'--content-handlers=%s' % ','.join(content_handlers),
'--url-mappings=mojo:window_manager=mojo:sky_debugger',
'mojo:window_manager',
]
if args.url:
url = args.url
if not urlparse.urlparse(url).scheme:
url = start_http_server_for_file(url)
prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % url
shell_command.append(prompt_args)
if args.gdb:
shell_command = ['gdb', '--args'] + shell_command
print ' '.join(shell_command)
subprocess.check_call(shell_command)
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
print "Quitting"