From e5b9b4be466d90dccfbd971cc16f72aa974f928d Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 24 Mar 2022 14:17:46 +0100 Subject: [PATCH] Moving update-env.sh to root, --- requirements.txt | 1 - scripts/update-env.sh => update-env.sh | 102 +++++++++++++++---------- 2 files changed, 62 insertions(+), 41 deletions(-) rename scripts/update-env.sh => update-env.sh (83%) diff --git a/requirements.txt b/requirements.txt index 95f4c07..926cb21 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ paramiko dnspython flake8 setuptools -chardet hjson toml fb_logging diff --git a/scripts/update-env.sh b/update-env.sh similarity index 83% rename from scripts/update-env.sh rename to update-env.sh index 5cacb0a..63bf221 100755 --- a/scripts/update-env.sh +++ b/update-env.sh @@ -17,16 +17,17 @@ GREEN="" CYAN="" NORMAL="" -BASENAME=$(basename "${0}" ) -BASE_DIR=$( dirname "$( dirname "$0" )" ) -cd "${BASE_DIR}" +BASENAME=$(basename "${0}") +BASE_DIR=$( dirname "$0" ) +cd "${BASE_DIR}" || exit 99 BASE_DIR=$( readlink -f . ) -declare -a VALID_PY_VERSIONS=("3.9" "3.8" "3.7" "3.6") - PIP_OPTIONS= export VIRTUAL_ENV_DISABLE_PROMPT=y +declare -a VALID_PY_VERSIONS=("3.10" "3.9" "3.8" "3.7" "3.6") +PYTHON= + #------------------------------------------------------------------- detect_color() { @@ -55,12 +56,13 @@ detect_color() { # console colors: if [ "${use_color}" = "true" ] ; then - RED="\033[38;5;196m" - YELLOW="\033[38;5;226m" - GREEN="\033[38;5;46m" - # BLUE="\033[38;5;27m" - CYAN="\033[38;5;36m" - NORMAL="\033[39m" + RED="\\033[38;5;196m" + YELLOW="\\033[38;5;226m" + GREEN="\\033[38;5;46m" + # BLUE="\\033[38;5;27m" + CYAN="\\033[38;5;36m" + NORMAL="\\033[39m" + # HAS_COLORS="y" else RED="" YELLOW="" @@ -71,7 +73,8 @@ detect_color() { fi local my_tty - my_tty=$( tty ) + + my_tty=$(tty) if [[ "${my_tty}" =~ 'not a tty' ]] ; then my_tty='-' fi @@ -79,7 +82,6 @@ detect_color() { } detect_color -#------------------------------------------------------------------------------ my_date() { date +'%F %T.%N %:::z' } @@ -173,6 +175,9 @@ get_options() { local tmp= local short_options="dvqhV" local long_options="debug,verbose,quiet,help,version" + local py_version= + local py_found="n" + local ret= set +e tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" ) @@ -205,6 +210,7 @@ get_options() { # BLUE="" CYAN="" NORMAL="" + # HAS_COLORS="n" shift ;; --nocolor) @@ -214,6 +220,7 @@ get_options() { # BLUE="" CYAN="" NORMAL="" + # HAS_COLORS="n" shift ;; -h|--help) @@ -246,6 +253,27 @@ get_options() { exit 1 fi + py_found="n" + info "Searching for valid Python …" + for py_version in "${VALID_PY_VERSIONS[@]}" ; do + PYTHON="python${py_version}" + debug "Testing Python binary '${CYAN}${PYTHON}${NORMAL}' …" + if type -t "${PYTHON}" >/dev/null ; then + py_found="y" + empty_line + info "Found '${GREEN}${PYTHON}${NORMAL}'." + break + fi + done + + if [[ "${py_found}" == "n" ]] ; then + empty_line >&2 + error "Did not found a usable Python version." >&2 + error "Usable Python versions are: ${YELLOW}${VALID_PY_VERSIONS[*]}${NORMAL}." >&2 + empty_line >&2 + exit 5 + fi + if type -t msgfmt >/dev/null ; then : else @@ -264,10 +292,6 @@ get_options() { #------------------------------------------------------------------------------ init_venv() { - local py_version= - local python= - local found="n" - empty_line line info "Preparing virtual environment …" @@ -275,30 +299,16 @@ init_venv() { if [[ ! -f venv/bin/activate ]] ; then - found="n" - for py_version in "${VALID_PY_VERSIONS[@]}" ; do - python="python${py_version}" - debug "Testing Python binary '${CYAN}${python}${NORMAL}' …" - if type -t "${python}" >/dev/null ; then - found="y" - empty_line - info "Found '${GREEN}${python}${NORMAL}'." - empty_line - "${python}" -m venv venv - break - fi - done - if [[ "${found}" == "n" ]] ; then - empty_line >&2 - error "Did not found a usable Python version." >&2 - error "Usable Python versions are: ${YELLOW}${VALID_PY_VERSIONS[*]}${NORMAL}." >&2 - empty_line >&2 - exit 5 - fi + + empty_line + "${PYTHON}" -m venv venv + fi # shellcheck disable=SC1091 . venv/bin/activate || exit 5 + debug "Which pip: $(command -v pip)" + debug "Which python: $(command -v python)" } @@ -344,11 +354,23 @@ list_modules() { #------------------------------------------------------------------------------ compile_i18n() { - if [[ -x bin/compile-xlate-msgs.sh ]]; then + if [[ -x compile-xlate-msgs.sh ]]; then + line + info "Updating i18n files in ${BASE_DIR} …" + empty_line + ./compile-xlate-msgs.sh + empty_line + fi +} + +#------------------------------------------------------------------------------ +compile_i18n() { + + if [[ -x compile-xlate-msgs.sh ]]; then line info "Updating i18n files in ${BASE_DIR} …" empty_line - bin/compile-xlate-msgs.sh + ./compile-xlate-msgs.sh empty_line fi } @@ -380,4 +402,4 @@ main "$@" exit 0 -# vim: ts=4 list +# vim: ts=4 -- 2.39.5