Merge pull request #822 from AndreMiras/feature/refactor_auto_accept_license

refactor auto accept license
This commit is contained in:
Alexander Taylor 2019-02-10 13:23:39 +00:00 committed by GitHub
commit afebba5f3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,18 +99,7 @@ class TargetAndroid(Target):
"""Call the sdkmanager in our Android SDK with the given arguments.""" """Call the sdkmanager in our Android SDK with the given arguments."""
# Use the android-sdk dir as cwd by default # Use the android-sdk dir as cwd by default
kwargs['cwd'] = kwargs.get('cwd', self.android_sdk_dir) kwargs['cwd'] = kwargs.get('cwd', self.android_sdk_dir)
command = self.sdkmanager_path + ' ' + ' '.join(args)
sdkmanager_path = os.path.join(self.android_sdk_dir,
'tools',
'bin',
'sdkmanager')
if not os.path.isfile(sdkmanager_path):
raise BuildozerException(
('sdkmanager path "{}" does not exist, sdkmanager is not'
'installed'.format(sdkmanager_path)))
command = sdkmanager_path + ' ' + ' '.join(args)
return_child = kwargs.pop('return_child', False) return_child = kwargs.pop('return_child', False)
if return_child: if return_child:
return self.buildozer.cmd_expect(command, **kwargs) return self.buildozer.cmd_expect(command, **kwargs)
@ -164,6 +153,16 @@ class TargetAndroid(Target):
return join(self.buildozer.global_platform_dir, return join(self.buildozer.global_platform_dir,
'apache-ant-{0}'.format(version)) 'apache-ant-{0}'.format(version))
@property
def sdkmanager_path(self):
sdkmanager_path = join(
self.android_sdk_dir, 'tools', 'bin', 'sdkmanager')
if not os.path.isfile(sdkmanager_path):
raise BuildozerException(
('sdkmanager path "{}" does not exist, sdkmanager is not'
'installed'.format(sdkmanager_path)))
return sdkmanager_path
def check_requirements(self): def check_requirements(self):
if platform in ('win32', 'cygwin'): if platform in ('win32', 'cygwin'):
try: try:
@ -457,30 +456,17 @@ class TargetAndroid(Target):
def _android_update_sdk(self, *sdkmanager_commands): def _android_update_sdk(self, *sdkmanager_commands):
"""Update the tools and package-tools if possible""" """Update the tools and package-tools if possible"""
from pexpect import EOF
auto_accept_license = self.buildozer.config.getbooldefault( auto_accept_license = self.buildozer.config.getbooldefault(
'app', 'android.accept_sdk_license', False) 'app', 'android.accept_sdk_license', False)
if auto_accept_license: if auto_accept_license:
java_tool_options = environ.get('JAVA_TOOL_OPTIONS', '') # `SIGPIPE` is not being reported somehow, but `EPIPE` is.
env = os.environ.copy() # This leads to a stderr "Broken pipe" message which is harmless,
env.update({ # but doesn't look good on terminal, hence redirecting to /dev/null
'JAVA_TOOL_OPTIONS': java_tool_options + yes_command = 'yes 2>/dev/null'
' -Dfile.encoding=UTF-8' command = '{} | {} --licenses'.format(
}) yes_command, self.sdkmanager_path)
child = self._sdkmanager( self.buildozer.cmd(command, cwd=self.android_sdk_dir)
*sdkmanager_commands,
timeout=None,
return_child=True,
env=env)
while True:
index = child.expect([EOF, u'\(y/N\): '])
if index == 0:
break
child.sendline('y')
else:
# the user will be prompted to read and accept the license
self._sdkmanager(*sdkmanager_commands) self._sdkmanager(*sdkmanager_commands)
def _read_version_subdir(self, *args): def _read_version_subdir(self, *args):