Skip to content

Commit 5c4c25b

Browse files
committed
automated: lib: sh-test-lib: check python version
Add a generic way to check python version if a specific minimum version is needed. Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
1 parent 5312292 commit 5c4c25b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

automated/lib/sh-test-lib

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,3 +766,52 @@ check_config() {
766766
check_return "config_value_${c}"
767767
done
768768
}
769+
770+
major() {
771+
# shellcheck disable=SC2039
772+
local pv="${1}"
773+
echo "${pv}" | awk -F'.' '{print $1}'
774+
}
775+
776+
minor() {
777+
# shellcheck disable=SC2039
778+
local pv="${1}"
779+
echo "${pv}" | awk -F'.' '{print $2}'
780+
}
781+
782+
check_python_version() {
783+
# send in "python --version"
784+
local pv="${1}"
785+
python_version=$(echo "${pv}" | awk -F' ' '{print $NF}')
786+
# example "3.9"
787+
local min_version="${2}"
788+
local err="${3}"
789+
# shellcheck disable=SC2155
790+
local x="$(major "${python_version}")"
791+
# shellcheck disable=SC2155
792+
local y="$(minor "${python_version}")"
793+
# shellcheck disable=SC2155
794+
local mx="$(major "${min_version}")"
795+
# shellcheck disable=SC2155
796+
local my="$(minor "${min_version}")"
797+
# shellcheck disable=SC2155
798+
local str="Wrong Python version installed ${pv}"
799+
if [ "${x}" -lt "${mx}" ]; then
800+
if [ "${err}" = "Error" ]; then
801+
error_msg "${str}"
802+
else
803+
warn_msg "${str}"
804+
return
805+
fi
806+
fi
807+
808+
if [ "${y}" -lt "${my}" ]; then
809+
if [ "${x}" -le "${mx}" ]; then
810+
if [ "${err}" = "Error" ]; then
811+
error_msg "${str}"
812+
else
813+
warn_msg "${str}"
814+
fi
815+
fi
816+
fi
817+
}

0 commit comments

Comments
 (0)