From d738df4875e598cfbae816d350eef4867d4111ee Mon Sep 17 00:00:00 2001 From: Jocelyn Delalande Date: Sat, 17 Feb 2018 00:20:10 +0100 Subject: [PATCH] Switchs to python3 rebuilds the venv from scratch on upgrade. --- conf/ihatemoney.cfg | 2 +- scripts/_common.sh | 6 +++++- scripts/install | 2 +- scripts/upgrade | 21 +++++++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/conf/ihatemoney.cfg b/conf/ihatemoney.cfg index 8fe6342..f41f6ce 100644 --- a/conf/ihatemoney.cfg +++ b/conf/ihatemoney.cfg @@ -1,5 +1,5 @@ DEBUG = True -SQLALCHEMY_DATABASE_URI = 'mysql://ihatemoney:MY_MYSQL_PW@localhost/ihatemoney' +SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://ihatemoney:MY_MYSQL_PW@localhost/ihatemoney' SQLACHEMY_ECHO = DEBUG SECRET_KEY = "MY_SECRET_KEY" diff --git a/scripts/_common.sh b/scripts/_common.sh index d12333f..4072135 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -43,7 +43,7 @@ fix_permissions() { install_apt_dependencies() { - sudo apt-get install -y -qq python-dev python-virtualenv supervisor libmysqlclient-dev + sudo apt-get install -y -qq python3-dev python3-virtualenv supervisor libmysqlclient-dev } create_unix_user() { @@ -58,6 +58,10 @@ create_system_dirs() { sudo mkdir -p /opt/yunohost } +init_virtualenv () { + sudo virtualenv /opt/yunohost/ihatemoney/venv --python /usr/bin/python3 +} + ### Backported helpers (from testing) diff --git a/scripts/install b/scripts/install index af2adf6..8537242 100755 --- a/scripts/install +++ b/scripts/install @@ -64,7 +64,7 @@ create_unix_user fetch_and_extract /opt/yunohost/ihatemoney/src/ ihatemoney # Prepare venv -sudo virtualenv /opt/yunohost/ihatemoney/venv +init_virtualenv sudo /opt/yunohost/ihatemoney/venv/bin/pip install -r /opt/yunohost/ihatemoney/src/requirements.txt sudo /opt/yunohost/ihatemoney/venv/bin/pip install gunicorn>=19.3.0 MySQL-python diff --git a/scripts/upgrade b/scripts/upgrade index 501a948..7f0bd8d 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -41,9 +41,11 @@ fix_permissions ${INSTALL_DIR}/src-new/ # Upgrade dependencies sudo ${PIP} install -r ${NEW_REQUIREMENTS} +sudo ${PIP} install gunicorn>=19.3.0 MySQL-python # Everything went ok ? Let's keep this code. sudo rm -rf ${INSTALL_DIR}/src +sudo rm -rf ${INSTALL_DIR}/venv-old sudo mv ${INSTALL_DIR}/src-new ${INSTALL_DIR}/src @@ -61,8 +63,23 @@ fi # (ihatemoney now read its conf by default from /etc/ihatemoney/ihatemoney.cfg) sudo rm -f ${INSTALL_DIR}/src/budget/settings.py -# Settings are not very likely to change, and that script may be -# adapted to handle it in case. + + +# MIGRATION: Optionaly switch to a python3 venv + +if [ ${INSTALL_DIR}/venv/bin/python -ef ${INSTALL_DIR}/venv/bin/python2 ] +then + install_apt_dependencies + # Trash py2 venv + sudo mv ${INSTALL_DIR}/venv ${INSTALL_DIR}/venv-old + init_virtualenv + + # Clears all cookie-sessions, because py2 & py3 sessions are incompatible + # Relates https://github.com/lepture/flask-wtf/issues/279 (fix unreleased) + new_secret_key=`openssl rand -base64 32` + sudo sed -i "s/SECRET_KEY = \".*\"/SECRET_KEY = \"${new_secret_key}\"/g" /etc/ihatemoney/ihatemoney.cfg +fi + # Restart backend sudo supervisorctl restart budget