Skip to content

Commit

Permalink
Change the logic to auto accept the SDK licenses, to avoid the shell=…
Browse files Browse the repository at this point in the history
…True usage
  • Loading branch information
misl6 committed Jul 13, 2022
1 parent be6817e commit 4a14335
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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'.
Expand Down
21 changes: 11 additions & 10 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 4a14335

Please sign in to comment.