Commit bd125e2e authored by Ian Fischer's avatar Ian Fischer

Return 0 or 2 from start and install commands.

parent 1245aa79
...@@ -198,17 +198,23 @@ class InstallSky(object): ...@@ -198,17 +198,23 @@ class InstallSky(object):
def run(self, args, pids): def run(self, args, pids):
android = AndroidDevice() android = AndroidDevice()
installed_somewhere = False
# Install on connected Android device # Install on connected Android device
if android.is_connected() and args.android_build_available: if android.is_connected() and args.android_build_available:
android.install_apk(android.get_apk_path(args)) installed_somewhere = installed_somewhere or android.install_apk(android.get_apk_path(args))
# Install on connected iOS device # Install on connected iOS device
if IOSDevice.is_connected() and args.ios_build_available: if IOSDevice.is_connected() and args.ios_build_available:
IOSDevice.install_app(IOSDevice.get_app_path(args)) installed_somewhere = installed_somewhere or IOSDevice.install_app(IOSDevice.get_app_path(args))
# Install on iOS simulator if it's running # Install on iOS simulator if it's running
if IOSSimulator.is_booted() and args.ios_sim_build_available: if IOSSimulator.is_booted() and args.ios_sim_build_available:
IOSSimulator.fork_install_app(IOSSimulator.get_app_path(args)) installed_somewhere = installed_somewhere or IOSSimulator.fork_install_app(IOSSimulator.get_app_path(args))
if installed_somewhere:
return 0
else:
return 2
# TODO(iansf): get rid of need for args # TODO(iansf): get rid of need for args
def needs_install(self, args): def needs_install(self, args):
...@@ -226,13 +232,14 @@ class StartSky(object): ...@@ -226,13 +232,14 @@ class StartSky(object):
start_parser.set_defaults(func=self.run) start_parser.set_defaults(func=self.run)
def run(self, args, pids): def run(self, args, pids):
started_sky_somewhere = False
if not args.poke: if not args.poke:
StopSky().run(args, pids) StopSky().run(args, pids)
# Only install if the user did not specify a poke # Only install if the user did not specify a poke
installer = InstallSky() installer = InstallSky()
if installer.needs_install(args): if installer.needs_install(args):
installer.run(args, pids) started_sky_somewhere = (installer.run(args, pids) == 0)
project_or_path = os.path.abspath(args.project_or_path) project_or_path = os.path.abspath(args.project_or_path)
...@@ -258,7 +265,12 @@ class StartSky(object): ...@@ -258,7 +265,12 @@ class StartSky(object):
android = AndroidDevice() android = AndroidDevice()
# TODO(iansf): fix this so that we don't have to pass sky_server_root, main_dart, pid, and args. # TODO(iansf): fix this so that we don't have to pass sky_server_root, main_dart, pid, and args.
android.setup_servers(sky_server_root, main_dart, pids, args) started_sky_on_android = android.setup_servers(sky_server_root, main_dart, pids, args)
if started_sky_somewhere or started_sky_on_android:
return 0
else:
return 2
class StopSky(object): class StopSky(object):
...@@ -420,7 +432,7 @@ class AndroidDevice(object): ...@@ -420,7 +432,7 @@ class AndroidDevice(object):
def install_apk(self, apk_path): def install_apk(self, apk_path):
if not os.path.exists(apk_path): if not os.path.exists(apk_path):
logging.error('"%s" does not exist.' % apk_path) logging.error('"%s" does not exist.' % apk_path)
return return False
cmd = [self.adb_path, 'install', '-r', apk_path] cmd = [self.adb_path, 'install', '-r', apk_path]
logging.info(' '.join(cmd)) logging.info(' '.join(cmd))
...@@ -433,10 +445,13 @@ class AndroidDevice(object): ...@@ -433,10 +445,13 @@ class AndroidDevice(object):
logging.info(' '.join(cmd)) logging.info(' '.join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
return True
# TODO(iansf): refactor setup_servers # TODO(iansf): refactor setup_servers
def setup_servers(self, sky_server_root, main_dart, pids, args): def setup_servers(self, sky_server_root, main_dart, pids, args):
if not self.is_connected(): if not self.is_connected():
return return False
# Set up port forwarding for observatory # Set up port forwarding for observatory
observatory_port_string = 'tcp:%s' % OBSERVATORY_PORT observatory_port_string = 'tcp:%s' % OBSERVATORY_PORT
...@@ -490,6 +505,8 @@ class AndroidDevice(object): ...@@ -490,6 +505,8 @@ class AndroidDevice(object):
logging.info(' '.join(cmd)) logging.info(' '.join(cmd))
subprocess.check_output(cmd) subprocess.check_output(cmd)
return True
def logs(self, clear=False): def logs(self, clear=False):
def do_logs(): def do_logs():
if clear: if clear:
...@@ -582,7 +599,7 @@ class IOSDevice(object): ...@@ -582,7 +599,7 @@ class IOSDevice(object):
@classmethod @classmethod
def install_app(cls, ios_app_path): def install_app(cls, ios_app_path):
if not cls.has_ios_deploy(): if not cls.has_ios_deploy():
return return False
try: try:
cmd = [ cmd = [
'ios-deploy', 'ios-deploy',
...@@ -595,7 +612,8 @@ class IOSDevice(object): ...@@ -595,7 +612,8 @@ class IOSDevice(object):
logging.info(' '.join(cmd)) logging.info(' '.join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
pass return False
return True
@classmethod @classmethod
def copy_file(cls, bundle_id, local_path, device_path): def copy_file(cls, bundle_id, local_path, device_path):
...@@ -782,6 +800,7 @@ class IOSSimulator(object): ...@@ -782,6 +800,7 @@ class IOSSimulator(object):
@classmethod @classmethod
def fork_install_app(cls, ios_app_path): def fork_install_app(cls, ios_app_path):
try:
cmd = [ cmd = [
os.path.abspath(__file__), os.path.abspath(__file__),
'ios_sim', 'ios_sim',
...@@ -791,6 +810,9 @@ class IOSSimulator(object): ...@@ -791,6 +810,9 @@ class IOSSimulator(object):
] ]
logging.info(' '.join(cmd)) logging.info(' '.join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
return True
except subprocess.CalledProcessError:
return False
def _process_args(self, args): def _process_args(self, args):
if args.ios_sim_build_path is None: if args.ios_sim_build_path is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment