Skip to content

Commit

Permalink
automated: lib: sh-test-lib: check python version
Browse files Browse the repository at this point in the history
Add a generic way to check python version if a specific minimum version
is needed.

Signed-off-by: Anders Roxell <[email protected]>
  • Loading branch information
roxell committed Aug 11, 2023
1 parent 5312292 commit dfef2f3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions automated/lib/sh-test-lib
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,47 @@ 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"
# shellcheck disable=SC2039
local pv=$(echo "${1}" | awk -F' ' '{print $NF}')
# example "3.9"
local min_version="${2}"
local err="${3}"
local x=$(major ${python_version})
local y=$(minor ${python_version})
local mx=$(major ${min_version})
local my=$(minor ${min_version})
local str="Wrong Python version installed $(python --version)"
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
}

0 comments on commit dfef2f3

Please sign in to comment.