Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android check python version #460

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions automated/android/apk-automation/apk-automation.sh
Expand Up @@ -42,7 +42,7 @@ if [ "${SKIP_INSTALL}" = "true" ] || [ "${SKIP_INSTALL}" = "True" ]; then
else
! check_root && error_msg "Please run this script as superuser!"
#install_deps "git python python-lxml python-pil python-setuptools python-requests python-matplotlib python-requests ca-certificates curl tar xz-utils" "${SKIP_INSTALL}"
install_deps "python3.9 python3-distutils git ca-certificates curl tar xz-utils" "${SKIP_INSTALL}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you want to drop .9 here?

install_deps "python3 python3-distutils git ca-certificates curl tar xz-utils" "${SKIP_INSTALL}"
if python3 --version|grep 'Python 3.6'; then
# Workaround for Ubuntu 18.04 Bionic version.
# ModuleNotFoundError: No module named 'distutils.cmd' needs python3-distutils
Expand All @@ -53,12 +53,13 @@ else
url_android_view_clien="https://github.com/dtmilano/AndroidViewClient"
fi

chech_python_version "$(python --verison)" "3.9" "Error"
curl "${url_pip}" -o get-pip.py
sudo python3 get-pip.py
sudo pip install virtualenv
pip --version
virenv_dir=python-workspace
virtualenv --python=python3.9 ${virenv_dir}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason to drop ".9" here?

virtualenv --python=python3 ${virenv_dir}
[ ! -d AndroidViewClient ] && git clone --depth 1 "${url_android_view_clien}"
# shellcheck disable=SC1090
source ${virenv_dir}/bin/activate
Expand Down
12 changes: 12 additions & 0 deletions automated/android/noninteractive-tradefed/setup.sh
Expand Up @@ -5,15 +5,23 @@
. ../../lib/sh-test-lib
. ../../lib/android-test-lib

SKIP_INSTALL=${1:-"false"}
JDK="openjdk-11-jdk-headless"
java_path="/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
if [ -n "${ANDROID_VERSION}" ] && echo "${ANDROID_VERSION}" | grep -q "aosp-android14"; then
# use openjdk-17 for Android14+ versions
JDK="openjdk-17-jdk-headless"
java_path="/usr/lib/jvm/java-17-openjdk-amd64/bin/java"
fi

PKG_DEPS="aapt apt-utils bzip2 coreutils curl git lib32gcc-s1-amd64-cross libcurl4 protobuf-compiler psmisc python3 python-is-python3 python3-lxml python3-pexpect python3-protobuf python3-setuptools sudo tar unzip usbutils wget xz-utils zip "

dist_name
case "${dist}" in
ubuntu)
dpkg --add-architecture i386
apt-get update -q
install_deps "${PKG_DEPS} ${JDK}" "${SKIP_INSTALL}"
# make sure to use the right java version
update-alternatives --set java ${java_path}
;;
Expand All @@ -22,6 +30,10 @@ case "${dist}" in
;;
esac

# Only aosp-master need the python version check.
if [ -n "${ANDROID_VERSION}" ] && echo "${ANDROID_VERSION}" | grep -q "aosp-master"; then
chech_python_version "$(python --verison)" "3.8" "Error"
fi
install_latest_adb
initialize_adb
adb_root
Expand Down
3 changes: 2 additions & 1 deletion automated/android/noninteractive-tradefed/tradefed.yaml
Expand Up @@ -14,6 +14,7 @@ metadata:
- functional

params:
SKIP_INSTALL: "false"
# Specify timeout in seconds for wait_boot_completed and wait_homescreen.
TIMEOUT: "300"
# Download CTS package or copy it from local disk.
Expand Down Expand Up @@ -46,7 +47,7 @@ run:
steps:
- cd ./automated/android/noninteractive-tradefed
# Run setup.sh in the original shell to reserve env variables.
- . ./setup.sh
- . ./setup.sh "${SKIP_INSTALL}"
- echo "after ./setup.sh"
# delete the test user to clean environment
- userdel testuser -r -f || true
Expand Down
49 changes: 49 additions & 0 deletions automated/lib/sh-test-lib
Expand Up @@ -766,3 +766,52 @@ check_config() {
check_return "config_value_${c}"
done
}

major() {
# shellcheck disable=SC2039
local pv="${1}"
echo "${pv}" | awk -F'.' '{print $1}'
}

minor() {
# shellcheck disable=SC2039
local pv="${1}"
echo "${pv}" | awk -F'.' '{print $2}'
}

check_python_version() {
# send in "python --version"
local pv="${1}"
python_version=$(echo "${pv}" | awk -F' ' '{print $NF}')
# example "3.9"
local min_version="${2}"
local err="${3}"
# shellcheck disable=SC2155
local x="$(major "${python_version}")"
# shellcheck disable=SC2155
local y="$(minor "${python_version}")"
# shellcheck disable=SC2155
local mx="$(major "${min_version}")"
# shellcheck disable=SC2155
local my="$(minor "${min_version}")"
# shellcheck disable=SC2155
local str="Wrong Python version installed ${pv}"
if [ "${x}" -lt "${mx}" ]; then
if [ "${err}" = "Error" ]; then
error_msg "${str}"
else
warn_msg "${str}"
return
fi
fi

if [ "${y}" -lt "${my}" ]; then
if [ "${x}" -le "${mx}" ]; then
if [ "${err}" = "Error" ]; then
error_msg "${str}"
else
warn_msg "${str}"
fi
fi
fi
}