| 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 subprocess | 8 import subprocess |
| 9 import sys | 9 import sys |
| 10 import urlparse | 10 import urlparse |
| 11 | 11 |
| 12 | 12 |
| 13 BUILD_DIRECTORY = 'out' | 13 BUILD_DIRECTORY = 'out' |
| 14 CONFIG_DIRECTORY = 'Debug' | 14 CONFIG_DIRECTORY = 'Debug' |
| 15 MOJO_SHELL_PATH = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, | 15 SKY_TOOLS_DIRECTORY = os.path.abspath(os.path.join(__file__, os.pardir)) |
| 16 MOJO_SHELL_PATH = os.path.abspath(os.path.join(SKY_TOOLS_DIRECTORY, os.pardir, |
| 16 os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell')) | 17 os.pardir, BUILD_DIRECTORY, CONFIG_DIRECTORY, 'mojo_shell')) |
| 17 | 18 |
| 18 SUPPORTED_MIME_TYPES = [ | 19 SUPPORTED_MIME_TYPES = [ |
| 19 'text/html', | 20 'text/html', |
| 20 'text/sky', | 21 'text/sky', |
| 21 'text/plain', | 22 'text/plain', |
| 22 ] | 23 ] |
| 23 | 24 |
| 24 def start_http_server_for_file(path): | 25 def start_http_server_for_file(path): |
| 25 HTTP_PORT = 9999 | 26 HTTP_PORT = 9999 |
| 26 directory = os.path.dirname(os.path.abspath(path)) | |
| 27 server_command = [ | 27 server_command = [ |
| 28 'python', | 28 os.path.join(SKY_TOOLS_DIRECTORY, 'sky_server'), |
| 29 '-m', | 29 os.path.dirname(os.path.abspath(path)), |
| 30 'SimpleHTTPServer', | 30 str(HTTP_PORT), |
| 31 str(HTTP_PORT) | |
| 32 ] | 31 ] |
| 33 subprocess.Popen(server_command, cwd=directory) | 32 subprocess.Popen(server_command) |
| 34 return 'http://localhost:%s/%s' % (HTTP_PORT, os.path.basename(path)) | 33 return 'http://localhost:%s/%s' % (HTTP_PORT, os.path.basename(path)) |
| 35 | 34 |
| 36 | 35 |
| 37 def main(): | 36 def main(): |
| 38 parser = argparse.ArgumentParser(description='Sky launcher/debugger') | 37 parser = argparse.ArgumentParser(description='Sky launcher/debugger') |
| 39 parser.add_argument('--gdb', action='store_true') | 38 parser.add_argument('--gdb', action='store_true') |
| 40 parser.add_argument('url', nargs='?', type=str) | 39 parser.add_argument('url', nargs='?', type=str) |
| 41 args = parser.parse_args() | 40 args = parser.parse_args() |
| 42 | 41 |
| 43 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') | 42 content_handlers = ['%s,%s' % (mime_type, 'mojo://sky_viewer/') |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % url | 56 prompt_args = '--args-for=mojo://sky_debugger_prompt/ %s' % url |
| 58 shell_command.append(prompt_args) | 57 shell_command.append(prompt_args) |
| 59 if args.gdb: | 58 if args.gdb: |
| 60 shell_command = ['gdb', '--args'] + shell_command | 59 shell_command = ['gdb', '--args'] + shell_command |
| 61 | 60 |
| 62 print ' '.join(shell_command) | 61 print ' '.join(shell_command) |
| 63 subprocess.check_call(shell_command) | 62 subprocess.check_call(shell_command) |
| 64 | 63 |
| 65 | 64 |
| 66 if __name__ == '__main__': | 65 if __name__ == '__main__': |
| 67 main() | 66 try: |
| 67 main() |
| 68 except (KeyboardInterrupt, SystemExit): |
| 69 print "Quitting" |
| OLD | NEW |