android: if multiples devices are plugged, deploy and run on all of them. except if a ANDROID_SERIAL env is set.

This commit is contained in:
Mathieu Virbel 2013-05-04 19:32:11 +02:00
parent 2a8dd715ef
commit 5474accca1

View file

@ -19,6 +19,7 @@ import traceback
from pipes import quote
from sys import platform, executable
from buildozer.target import Target
from os import environ
from os.path import join, realpath, expanduser
from shutil import copyfile
@ -410,6 +411,21 @@ class TargetAndroid(Target):
self.buildozer.state['android:latestapk'] = apk
self.buildozer.state['android:latestmode'] = self.build_mode
@property
def serials(self):
if hasattr(self, '_serials'):
return self._serials
serial = environ.get('ANDROID_SERIAL')
if serial:
return [serial]
l = self.buildozer.cmd('adb devices',
get_stdout=True)[0].splitlines()[1:-1]
serials = []
for serial in l:
serials.append(serial.split()[0])
self._serials = serials
return serials
def cmd_deploy(self, *args):
super(TargetAndroid, self).cmd_deploy(*args)
state = self.buildozer.state
@ -429,10 +445,14 @@ class TargetAndroid(Target):
'Unable to found the latest APK. Please run "debug" again.')
# push on the device
self.buildozer.cmd('{0} install -r {1}'.format(
self.adb_cmd, full_apk), cwd=self.buildozer.global_platform_dir)
for serial in self.serials:
self.buildozer.environ['ANDROID_SERIAL'] = serial
self.buildozer.info('Deploy on {}'.format(serial))
self.buildozer.cmd('{0} install -r {1}'.format(
self.adb_cmd, full_apk), cwd=self.buildozer.global_platform_dir)
self.buildozer.environ.pop('ANDROID_SERIAL', None)
self.buildozer.info('Application pushed on the device.')
self.buildozer.info('Application pushed.')
def cmd_run(self, *args):
super(TargetAndroid, self).cmd_run(*args)
@ -441,20 +461,30 @@ class TargetAndroid(Target):
'app', 'android.entrypoint', 'org.renpy.android.PythonActivity')
package = self._get_package()
self.buildozer.cmd(
'{adb} shell am start -n {package}/{entry} -a {entry}'.format(
adb=self.adb_cmd, package=package, entry=entrypoint),
cwd=self.buildozer.global_platform_dir)
# push on the device
for serial in self.serials:
self.buildozer.environ['ANDROID_SERIAL'] = serial
self.buildozer.info('Run on {}'.format(serial))
self.buildozer.cmd(
'{adb} shell am start -n {package}/{entry} -a {entry}'.format(
adb=self.adb_cmd, package=package, entry=entrypoint),
cwd=self.buildozer.global_platform_dir)
self.buildozer.environ.pop('ANDROID_SERIAL', None)
self.buildozer.info('Application started on the device.')
self.buildozer.info('Application started.')
def cmd_logcat(self, *args):
'''Show the log from the device
'''
self.check_requirements()
serial = self.serials[0:]
if not serial:
return
self.buildozer.environ['ANDROID_SERIAL'] = serial[0]
self.buildozer.cmd('{adb} logcat'.format(adb=self.adb_cmd),
cwd=self.buildozer.global_platform_dir,
show_output=True)
self.buildozer.environ.pop('ANDROID_SERIAL', None)