| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 json | 7 import json |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import signal | 11 import signal |
| 12 import socket | 12 import socket |
| 13 import subprocess | 13 import subprocess |
| 14 import sys | 14 import sys |
| 15 import urlparse | 15 import urlparse |
| 16 import time | 16 import time |
| 17 | 17 |
| 18 # TODO(eseidel): This should be BIN_DIR. | 18 # TODO(eseidel): This should be BIN_DIR. |
| 19 LIB_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__))) | 19 LIB_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__))) |
| 20 SKY_PACKAGE_ROOT = os.path.realpath(os.path.dirname(LIB_DIR)) | 20 SKY_PACKAGE_ROOT = os.path.realpath(os.path.dirname(LIB_DIR)) |
| 21 | 21 |
| 22 SKY_SERVER_PORT = 9888 | 22 SKY_SERVER_PORT = 9888 |
| 23 OBSERVATORY_PORT = 8181 |
| 23 APK_NAME = 'SkyDemo.apk' | 24 APK_NAME = 'SkyDemo.apk' |
| 24 ANDROID_PACKAGE = "org.domokit.sky.demo" | 25 ANDROID_PACKAGE = "org.domokit.sky.demo" |
| 25 # FIXME: This assumes adb is in $PATH, we could look for ANDROID_HOME, etc? | 26 # FIXME: This assumes adb is in $PATH, we could look for ANDROID_HOME, etc? |
| 26 ADB_PATH = 'adb' | 27 ADB_PATH = 'adb' |
| 27 # FIXME: Do we need to look in $DART_SDK? | 28 # FIXME: Do we need to look in $DART_SDK? |
| 28 DART_PATH = 'dart' | 29 DART_PATH = 'dart' |
| 29 | 30 |
| 30 PID_FILE_PATH = "/tmp/sky_tool.pids" | 31 PID_FILE_PATH = "/tmp/sky_tool.pids" |
| 31 PID_FILE_KEYS = frozenset([ | 32 PID_FILE_KEYS = frozenset([ |
| 32 'remote_sky_server_port', | 33 'remote_sky_server_port', |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 args.install = True | 163 args.install = True |
| 163 | 164 |
| 164 if args.install: | 165 if args.install: |
| 165 apk_path = os.path.join(SKY_PACKAGE_ROOT, 'apks', APK_NAME) | 166 apk_path = os.path.join(SKY_PACKAGE_ROOT, 'apks', APK_NAME) |
| 166 if not os.path.exists(apk_path): | 167 if not os.path.exists(apk_path): |
| 167 print "'%s' does not exist?" % apk_path | 168 print "'%s' does not exist?" % apk_path |
| 168 return 2 | 169 return 2 |
| 169 | 170 |
| 170 subprocess.check_call([ADB_PATH, 'install', '-r', apk_path]) | 171 subprocess.check_call([ADB_PATH, 'install', '-r', apk_path]) |
| 171 | 172 |
| 173 # Set up port forwarding for observatory |
| 174 observatory_port_string = 'tcp:%s' % OBSERVATORY_PORT |
| 175 subprocess.check_call([ |
| 176 ADB_PATH, 'forward', observatory_port_string, observatory_port_strin
g |
| 177 ]) |
| 178 |
| 172 sky_server_port = SKY_SERVER_PORT | 179 sky_server_port = SKY_SERVER_PORT |
| 173 pids['sky_server_port'] = sky_server_port | 180 pids['sky_server_port'] = sky_server_port |
| 174 if _port_in_use(sky_server_port): | 181 if _port_in_use(sky_server_port): |
| 175 logging.warn(('Port %s already in use. ' | 182 logging.warn(('Port %s already in use. ' |
| 176 ' Not starting server for %s') % (sky_server_port, sky_server_root)) | 183 ' Not starting server for %s') % (sky_server_port, sky_server_root)) |
| 177 else: | 184 else: |
| 178 sky_server_pid = _start_http_server(sky_server_port, sky_server_root
) | 185 sky_server_pid = _start_http_server(sky_server_port, sky_server_root
) |
| 179 pids['sky_server_pid'] = sky_server_pid | 186 pids['sky_server_pid'] = sky_server_pid |
| 180 pids['sky_server_root'] = sky_server_root | 187 pids['sky_server_root'] = sky_server_root |
| 181 | 188 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 args = parser.parse_args() | 308 args = parser.parse_args() |
| 302 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS) | 309 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS) |
| 303 exit_code = args.func(args, pids) | 310 exit_code = args.func(args, pids) |
| 304 # We could do this with an at-exit handler instead? | 311 # We could do this with an at-exit handler instead? |
| 305 pids.write_to(PID_FILE_PATH) | 312 pids.write_to(PID_FILE_PATH) |
| 306 sys.exit(exit_code) | 313 sys.exit(exit_code) |
| 307 | 314 |
| 308 | 315 |
| 309 if __name__ == '__main__': | 316 if __name__ == '__main__': |
| 310 SkyShellRunner().main() | 317 SkyShellRunner().main() |
| OLD | NEW |