Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Side by Side Diff: sky/sdk/packages/sky/lib/sky_tool

Issue 1022193002: Make the Sky pub package include our APK and teach sky_tool to install it (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add missing file Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/packages/sky/bin/sky ('k') | sky/tools/deploy_sdk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 signal 10 import signal
11 import socket 11 import socket
12 import subprocess 12 import subprocess
13 import sys 13 import sys
14 import urlparse 14 import urlparse
15 15
16 SDK_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) 16 # TODO(eseidel): This should be BIN_DIR.
17 SDK_ROOT = os.path.dirname(SDK_TOOLS_DIR) 17 LIB_DIR = os.path.realpath(os.path.dirname(os.path.abspath(__file__)))
18 SKY_PACKAGE_ROOT = os.path.realpath(os.path.dirname(LIB_DIR))
18 19
19 SKY_SERVER_PORT = 9888 20 SKY_SERVER_PORT = 9888
20 DEFAULT_URL = os.path.join(SDK_ROOT, "examples/index.sky")
21 APK_NAME = 'SkyDemo.apk' 21 APK_NAME = 'SkyDemo.apk'
22 ANDROID_PACKAGE = "org.domokit.sky.demo" 22 ANDROID_PACKAGE = "org.domokit.sky.demo"
23 # FIXME: This assumes adb is in $PATH, we could look for ANDROID_HOME, etc? 23 # FIXME: This assumes adb is in $PATH, we could look for ANDROID_HOME, etc?
24 ADB_PATH = 'adb' 24 ADB_PATH = 'adb'
25 25
26 PID_FILE_PATH = "/tmp/skydemo.pids" 26 PID_FILE_PATH = "/tmp/sky_tool.pids"
27 PID_FILE_KEYS = frozenset([ 27 PID_FILE_KEYS = frozenset([
28 'remote_sky_server_port', 28 'remote_sky_server_port',
29 'sky_server_pid', 29 'sky_server_pid',
30 'sky_server_port', 30 'sky_server_port',
31 'sky_server_root', 31 'sky_server_root',
32 'build_dir', 32 'build_dir',
33 ]) 33 ])
34 34
35 35
36 def _port_in_use(port): 36 def _port_in_use(port):
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 106
107 def _url_for_path(port, root, path): 107 def _url_for_path(port, root, path):
108 relative_path = os.path.relpath(path, root) 108 relative_path = os.path.relpath(path, root)
109 return 'sky://localhost:%s/%s' % (port, relative_path) 109 return 'sky://localhost:%s/%s' % (port, relative_path)
110 110
111 111
112 class StartSky(object): 112 class StartSky(object):
113 def add_subparser(self, subparsers): 113 def add_subparser(self, subparsers):
114 start_parser = subparsers.add_parser('start', 114 start_parser = subparsers.add_parser('start',
115 help='launch SKyShell.apk on the device') 115 help='launch %s on the device' % APK_NAME)
116 start_parser.add_argument('--install', action='store_true') 116 start_parser.add_argument('--install', action='store_true')
117 start_parser.add_argument('project_or_path', nargs='?', type=str, 117 start_parser.add_argument('project_or_path', nargs='?', type=str,
118 default='main.sky') 118 default='main.sky')
119 start_parser.set_defaults(func=self.run) 119 start_parser.set_defaults(func=self.run)
120 120
121 def _is_package_installed(self, package_name):
122 pm_path_cmd = [ADB_PATH, 'shell', 'pm', 'path', package_name]
123 return subprocess.check_output(pm_path_cmd).strip() != ''
124
121 def run(self, args, pids): 125 def run(self, args, pids):
122 StopSky().run(args, pids) 126 StopSky().run(args, pids)
127
128 if not self._is_package_installed(ANDROID_PACKAGE):
129 print '%s is not installed, installing.' % APK_NAME
130 args.install = True
131
123 if args.install: 132 if args.install:
124 apk_path = os.path.join(SDK_ROOT, 'apks', APK_NAME) 133 apk_path = os.path.join(SKY_PACKAGE_ROOT, 'apks', APK_NAME)
125 if not os.path.exists(apk_path): 134 if not os.path.exists(apk_path):
126 print "'%s' does not exist?" % apk_path 135 print "'%s' does not exist?" % apk_path
127 return 2 136 return 2
128 137
129 subprocess.check_call([ADB_PATH, 'install', '-r', apk_path]) 138 subprocess.check_call([ADB_PATH, 'install', '-r', apk_path])
130 139
131 project_or_path = os.path.abspath(args.project_or_path) 140 project_or_path = os.path.abspath(args.project_or_path)
132 141
133 if os.path.isdir(project_or_path): 142 if os.path.isdir(project_or_path):
134 sky_server_root = project_or_path 143 sky_server_root = project_or_path
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 args = parser.parse_args() 221 args = parser.parse_args()
213 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS) 222 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS)
214 exit_code = args.func(args, pids) 223 exit_code = args.func(args, pids)
215 # We could do this with an at-exit handler instead? 224 # We could do this with an at-exit handler instead?
216 pids.write_to(PID_FILE_PATH) 225 pids.write_to(PID_FILE_PATH)
217 sys.exit(exit_code) 226 sys.exit(exit_code)
218 227
219 228
220 if __name__ == '__main__': 229 if __name__ == '__main__':
221 SkyShellRunner().main() 230 SkyShellRunner().main()
OLDNEW
« no previous file with comments | « sky/sdk/packages/sky/bin/sky ('k') | sky/tools/deploy_sdk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698