From 87df116166aad48033ac5a2a030b13180a1024cf Mon Sep 17 00:00:00 2001 From: Jocelyn Delalande Date: Tue, 18 Dec 2018 18:24:07 +0100 Subject: [PATCH] Handle Python version change on upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whispers: Actually that is to handle Jessie → Strech upgrade, that switches from Py 3.4 to 3.5. --- conf/nginx.conf | 2 +- scripts/_common.sh | 3 +++ scripts/upgrade | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 0d9b249..3d13167 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ location PATHTOCHANGE/static/ { - alias /opt/yunohost/ihatemoney/venv/lib/python3.4/site-packages/ihatemoney/static/; + alias /opt/yunohost/ihatemoney/venv/lib/pythonPYTHON_VERSION/site-packages/ihatemoney/static/; } location PATHTOCHANGE { # Force https. diff --git a/scripts/_common.sh b/scripts/_common.sh index 42e551e..4b92e55 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -42,8 +42,11 @@ init_virtualenv () { configure_nginx () { local domain=$1 local path=$2 + local python_version="$(readlink /usr/bin/python3|sed s/.*python//)" + sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf + sed -i "s@PYTHON_VERSION@$python_version@g" ../conf/nginx.conf # Fix double-slash for domain-root install sed -i "s@location //@location /@" ../conf/nginx.conf sudo install -o root -g root -m644 \ diff --git a/scripts/upgrade b/scripts/upgrade index acbb0f7..a10e6a2 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -19,6 +19,8 @@ path=$(ynh_app_setting_get $app path) is_public=$(ynh_app_setting_get "$app" is_public) VENV_PY_VERSION=$(echo ${INSTALL_DIR}/venv/bin/python*.*|sed 's/.*python//') +SYSTEM_PY_VERSION=$(readlink /usr/bin/python3|sed s/.*python//) + # Source local utils source _common.sh @@ -67,6 +69,18 @@ fi +# MIGRATION: minor Py version has changed ? rebuilt venv + +# Useful for Py 3.4 → 3.5, Jessie → Stretch, ynh 2.x → 3.x +if [[ "$VENV_PY_VERSION" != '2.7' ]] && [[ "$VENV_PY_VERSION" != "$SYSTEM_PY_VERSION" ]] +then + sudo mv ${INSTALL_DIR}/venv ${INSTALL_DIR}/venv-old + init_virtualenv + + # the static path changed + configure_nginx "$domain" "$path" +fi + #-------------------------------UPGRADE-------------------------