diff --git a/buildozer/__init__.py b/buildozer/__init__.py index 6d12f9a15..319923a9b 100644 --- a/buildozer/__init__.py +++ b/buildozer/__init__.py @@ -26,6 +26,8 @@ from fnmatch import fnmatch from pprint import pformat +import shlex +import pexpect from urllib.request import FancyURLopener from configparser import ConfigParser @@ -356,7 +358,6 @@ def cmd(self, command, **kwargs): process.returncode) def cmd_expect(self, command, **kwargs): - from pexpect import spawnu # prepare the environ, based on the system + our own env env = environ.copy() @@ -377,7 +378,7 @@ def cmd_expect(self, command, **kwargs): self.debug('Run (expect) {0!r} ...'.format(command.split()[0])) self.debug('Cwd {}'.format(kwargs.get('cwd'))) - return spawnu(command, **kwargs) + return pexpect.spawnu(shlex.join(command), **kwargs) def check_configuration_tokens(self): '''Ensure the spec file is 'correct'. diff --git a/buildozer/targets/android.py b/buildozer/targets/android.py index 548c765e9..3c7d10e61 100644 --- a/buildozer/targets/android.py +++ b/buildozer/targets/android.py @@ -32,6 +32,7 @@ from platform import architecture from shutil import copyfile, rmtree, which import shlex +import pexpect from glob import glob from time import sleep @@ -553,19 +554,19 @@ def _android_update_sdk(self, *sdkmanager_commands): kwargs = {} if auto_accept_license: - # `SIGPIPE` is not being reported somehow, but `EPIPE` is. - # This leads to a stderr "Broken pipe" message which is harmless, - # but doesn't look good on terminal, hence redirecting to /dev/null - yes_command = 'yes 2>/dev/null' - android_sdk_dir = self.android_sdk_dir - sdkmanager_path = self.sdkmanager_path - sdk_root = f"--sdk_root={android_sdk_dir}" - command = f"{yes_command} | {sdkmanager_path} {sdk_root} --licenses" - self.buildozer.cmd(command, cwd=self.android_sdk_dir, shell=True) + kwargs["return_child"] = True else: kwargs['show_output'] = True - self._sdkmanager(*sdkmanager_commands, **kwargs) + ret_child = self._sdkmanager(*sdkmanager_commands, **kwargs) + + if auto_accept_license: + while ret_child.isalive(): + pexp_match = ret_child.expect( + ["(y/N)", pexpect.EOF, pexpect.TIMEOUT], timeout=300 + ) + if pexp_match == 0: + ret_child.sendline("y") def _read_version_subdir(self, *args): versions = []