From 8db05d91f49531c87d9271e664452cc79912b5be Mon Sep 17 00:00:00 2001
From: Emmanuel Cazenave <ecazenave@entrouvert.com>
Date: Tue, 5 Nov 2019 13:04:18 +0100
Subject: [PATCH 2/2] run chrono and combo in python3 (#36894)

---
 clean.yml                                     |   7 +-
 group_vars/all                                |   1 +
 install.yml                                   |   3 +-
 install_source.yml                            |   4 +-
 roles/app-setup/tasks/main.yml                |   4 +-
 .../app-setup/templates/app-settings-base.j2  |   4 +-
 roles/authentic/tasks/main.yml                |   6 --
 roles/authentic/vars/main.yml                 |   1 +
 roles/base/tasks/main.yml                     | 102 +++++++++++++++++-
 roles/base/templates/getlasso.j2              |   4 +-
 roles/bijoe/vars/main.yml                     |   1 +
 roles/chrono/vars/main.yml                    |   3 +-
 roles/combo/tasks/main.yml                    |   5 -
 roles/combo/vars/main.yml                     |   3 +-
 roles/fargo/vars/main.yml                     |   1 +
 roles/hobo/tasks/main.yml                     |  22 ++--
 roles/hobo/vars/main.yml                      |   1 +
 roles/passerelle/tasks/main.yml               |   7 --
 roles/passerelle/vars/main.yml                |   1 +
 roles/wcs/vars/main.yml                       |   1 +
 roles/welco/vars/main.yml                     |   1 +
 21 files changed, 132 insertions(+), 50 deletions(-)

diff --git a/clean.yml b/clean.yml
index 97f121d..747898a 100644
--- a/clean.yml
+++ b/clean.yml
@@ -1,11 +1,16 @@
 ---
 - hosts: local
   tasks:
-    - name: delete venv
+    - name: delete python2 venv
       file:
         path: "{{venv}}"
         state: absent
 
+    - name: delete python3 venv
+      file:
+        path: "{{venv_py3}}"
+        state: absent
+
     - name: delete app /var/lib directory
       file:
         path: "/var/lib/{{item.value.project_name}}"
diff --git a/group_vars/all b/group_vars/all
index 12c1df1..6354478 100644
--- a/group_vars/all
+++ b/group_vars/all
@@ -8,6 +8,7 @@ src_dir: "/home/{{user}}/src"
 ssl_certificate: "{{venv_certs}}/dev.publik.love-fullchain.pem"
 ssl_certificate_key: "{{venv_certs}}/dev.publik.love-privkey.pem"
 venv: "/home/{{user}}/envs/publik-env"
+venv_py3: "/home/{{user}}/envs/publik-env-py3"
 user: your_user_name
 apps:
   authentic:
diff --git a/install.yml b/install.yml
index 85789bd..f00e640 100644
--- a/install.yml
+++ b/install.yml
@@ -18,7 +18,8 @@
   vars:
     themes_dir: "{{venv}}/themes"
     venv_bin: "{{venv}}/bin"
+    venv_py3_bin: "{{venv_py3}}/bin"
     venv_certs: "{{venv}}/certs"
-    venv_pip: "{{venv_bin}}/pip"
     venv_python: "{{venv_bin}}/python"
+    venv_py3_python: "{{venv_py3_bin}}/python"
     venv_share: "{{venv}}/share"
diff --git a/install_source.yml b/install_source.yml
index efa60b8..a152450 100644
--- a/install_source.yml
+++ b/install_source.yml
@@ -20,9 +20,9 @@
     name: django
     version: "{{ django_version}}"
     extra_args: "-e {{ repo_dir }}"
-    virtualenv: "{{ venv }}"
+    virtualenv: "{{ virtualenv }}"
 
 - name: "build {{ repo_dir }}"
-  command: "{{ venv_python }} setup.py build"
+  command: "{{ virtualenv }}/bin/python setup.py build"
   args:
     chdir: "{{ repo_dir }}"
diff --git a/roles/app-setup/tasks/main.yml b/roles/app-setup/tasks/main.yml
index bf2d93a..eae2313 100644
--- a/roles/app-setup/tasks/main.yml
+++ b/roles/app-setup/tasks/main.yml
@@ -2,7 +2,7 @@
   set_fact:
     app_settings: "{{publik_settings}}/{{project_name}}/settings.py"
     app_settings_dir: "{{publik_settings}}/{{project_name}}"
-    manage_app_bin: "{{venv_bin}}/{{project_name}}-manage"
+    manage_app_bin: "{{virtualenv}}/bin/{{project_name}}-manage"
     server_app_name: "{{project_name}}"
 
 - name: "{{app_name}} - create db"
@@ -90,7 +90,7 @@
 - name: "{{app_name}} - server script"
   template:
     src: app-server.j2
-    dest: "{{venv_bin}}/{{server_app_name}}-server"
+    dest: "{{virtualenv}}/bin/{{server_app_name}}-server"
     mode: "u=rwx,g=rx,o=rx"
   
 - name: "{{app_name}} - server log directory"
diff --git a/roles/app-setup/templates/app-settings-base.j2 b/roles/app-setup/templates/app-settings-base.j2
index d2ffd43..ede0990 100644
--- a/roles/app-setup/templates/app-settings-base.j2
+++ b/roles/app-setup/templates/app-settings-base.j2
@@ -10,7 +10,7 @@ import os
 
 PROJECT_NAME = "{{project_name}}"
 
-execfile('{{src_dir}}/hobo/debian/debian_config_common.py')
+exec(open('{{src_dir}}/hobo/debian/debian_config_common.py').read())
 
 THEMES_DIRECTORY = '{{themes_dir}}'
 
@@ -64,4 +64,4 @@ DEBUG = True
 
 for filename in sorted(
     glob.glob(os.path.join('{{app_settings_dir}}', 'settings.d', '*.py'))):
-    execfile(filename)
+    exec(open(filename).read())
diff --git a/roles/authentic/tasks/main.yml b/roles/authentic/tasks/main.yml
index e5fc7a0..2f5c7de 100644
--- a/roles/authentic/tasks/main.yml
+++ b/roles/authentic/tasks/main.yml
@@ -5,12 +5,6 @@
     repo: "authentic"
     repo_dir: "{{ src_dir }}/authentic"
 
-# FIXME: change authentic settings instead ?
-- name: install python-memcached
-  pip:
-    name: python-memcached
-    virtualenv: "{{venv}}"
-
 - name: source install authentic2-auth-fc
   import_tasks: install_source.yml
   vars:
diff --git a/roles/authentic/vars/main.yml b/roles/authentic/vars/main.yml
index 6af4abe..b0f4d3a 100644
--- a/roles/authentic/vars/main.yml
+++ b/roles/authentic/vars/main.yml
@@ -8,3 +8,4 @@ nginx_template_name: "std-nginx-server.j2"
 project_name: "{{apps['authentic']['project_name']}}"
 server_port: "{{apps['authentic']['server_port']}}"
 settings_env_var: AUTHENTIC2_SETTINGS_FILE
+virtualenv: "{{venv}}"
diff --git a/roles/base/tasks/main.yml b/roles/base/tasks/main.yml
index 0f5449d..924a55a 100644
--- a/roles/base/tasks/main.yml
+++ b/roles/base/tasks/main.yml
@@ -42,17 +42,29 @@
   become: yes
   become_user: postgres
 
-- name: create the virtualenv and install django
+- name: create the py2 virtualenv and install django
   pip:
     name: django
     version: "{{django_version}}"
     virtualenv: "{{venv}}"
 
-- name: install django-debug-toolbar
+- name: create the py3 virtualenv and install django
+  pip:
+    name: django
+    version: "{{django_version}}"
+    virtualenv: "{{venv_py3}}"
+    virtualenv_python: python3
+
+- name: install django-debug-toolbar in python2
   pip:
     name: django-debug-toolbar
     virtualenv: "{{venv}}"
 
+- name: install django-debug-toolbar in python3
+  pip:
+    name: django-debug-toolbar
+    virtualenv: "{{venv_py3}}"
+
 - name: "create {{src_dir}} directory"
   file:
     path: "{{src_dir}}"
@@ -80,20 +92,102 @@
     path: "{{publik_settings}}"
     state: directory
 
-- name: create getlasso script
+- name: create getlasso script in python2
   template:
     src: getlasso.j2
     dest: "{{venv_bin}}/getlasso.sh"
     mode: "u=rwx,g=rx,o=rx"
+  vars:
+    virtualenv_python: "{{venv_python}}"
+    system_python: "/usr/bin/python"
+
+- name: create getlasso script in python3
+  template:
+    src: getlasso.j2
+    dest: "{{venv_py3_bin}}/getlasso.sh"
+    mode: "u=rwx,g=rx,o=rx"
+  vars:
+    virtualenv_python: "{{venv_py3_python}}"
+    system_python: "/usr/bin/python3"
 
-- name: execute getlasso
+- name: execute getlasso in python2
   command: "{{venv_bin}}/getlasso.sh"
 
+- name: execute getlasso in python3
+  command: "{{venv_py3_bin}}/getlasso.sh"
+
 - name: source install eopayment
   import_tasks: install_source.yml
   vars:
     repo: "eopayment"
     repo_dir: "{{ src_dir }}/eopayment"
+    virtualenv: "{{venv_py3}}"
+
+- name: source install django-tenant-schemas in python2 env
+  import_tasks: install_source.yml
+  vars:
+    repo: "debian/django-tenant-schemas"
+    repo_dir: "{{ src_dir }}/django-tenant-schemas"
+    virtualenv: "{{venv}}"
+
+- name: source install django-tenant-schemas in python3 env
+  import_tasks: install_source.yml
+  vars:
+    repo: "debian/django-tenant-schemas"
+    repo_dir: "{{ src_dir }}/django-tenant-schemas"
+    virtualenv: "{{venv_py3}}"
+
+- name: source install django-mellon in python2 env
+  import_tasks: install_source.yml
+  vars:
+    repo: "django-mellon"
+    repo_dir: "{{ src_dir }}/django-mellon"
+    virtualenv: "{{venv}}"
+
+- name: source install django-mellon in python3 env
+  import_tasks: install_source.yml
+  vars:
+    repo: "django-mellon"
+    repo_dir: "{{ src_dir }}/django-mellon"
+    virtualenv: "{{venv_py3}}"
+
+- name: source install gadjo in python2 env
+  import_tasks: install_source.yml
+  vars:
+    repo: "gadjo"
+    repo_dir: "{{ src_dir }}/gadjo"
+    virtualenv: "{{venv}}"
+
+- name: source install gadjo in python3 env
+  import_tasks: install_source.yml
+  vars:
+    repo: "gadjo"
+    repo_dir: "{{ src_dir }}/gadjo"
+    virtualenv: "{{venv_py3}}"
+
+- name: install memcache in python2
+  pip:
+    name: python-memcached
+    virtualenv: "{{venv}}"
+
+- name: install memcache in python3
+  pip:
+    name: python-memcached
+    virtualenv: "{{venv_py3}}"
+
+- name: source install django-ckeditor in python2
+  import_tasks: install_source.yml
+  vars:
+    repo: "debian/django-ckeditor"
+    repo_dir: "{{ src_dir }}/django-ckeditor"
+    virtualenv: "{{venv}}"
+
+- name: source install django-ckeditor in python3
+  import_tasks: install_source.yml
+  vars:
+    repo: "debian/django-ckeditor"
+    repo_dir: "{{ src_dir }}/django-ckeditor"
+    virtualenv: "{{venv_py3}}"
 
 - name: install theme
   import_tasks: tasks/install_theme.yml
diff --git a/roles/base/templates/getlasso.j2 b/roles/base/templates/getlasso.j2
index 6040733..c2246b2 100644
--- a/roles/base/templates/getlasso.j2
+++ b/roles/base/templates/getlasso.j2
@@ -1,9 +1,9 @@
 #!/bin/sh
 
 # Get venv site-packages path
-DSTDIR=`{{venv_python}} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
+DSTDIR=`{{virtualenv_python}} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
 
-SRCDIR=`/usr/bin/python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
+SRCDIR=`{{system_python}} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())'`
 
 # Clean up
 rm -f $DSTDIR/lasso.*
diff --git a/roles/bijoe/vars/main.yml b/roles/bijoe/vars/main.yml
index 3197c38..fc592dc 100644
--- a/roles/bijoe/vars/main.yml
+++ b/roles/bijoe/vars/main.yml
@@ -8,3 +8,4 @@ nginx_template_name: "std-nginx-server.j2"
 project_name: "{{apps['bijoe']['project_name']}}"
 server_port: "{{apps['bijoe']['server_port']}}"
 settings_env_var: BIJOE_SETTINGS_FILE
+virtualenv: "{{venv}}"
diff --git a/roles/chrono/vars/main.yml b/roles/chrono/vars/main.yml
index 466870e..cb2eba1 100644
--- a/roles/chrono/vars/main.yml
+++ b/roles/chrono/vars/main.yml
@@ -2,9 +2,10 @@ app_name: chrono
 compile_scss: false
 compile_translations: true
 db_name: "{{apps['chrono']['db_name']}}"
-manage_cmd: "{{venv_python}} {{src_dir}}/chrono/manage.py"
+manage_cmd: "{{venv_py3_python}} {{src_dir}}/chrono/manage.py"
 nginx_host_pattern: "{{apps['chrono']['nginx_host_pattern']}}"
 nginx_template_name: "chrono-nginx-server.j2"
 project_name: "{{apps['chrono']['project_name']}}"
 server_port: "{{apps['chrono']['server_port']}}"
 settings_env_var: CHRONO_SETTINGS_FILE
+virtualenv: "{{venv_py3}}"
diff --git a/roles/combo/tasks/main.yml b/roles/combo/tasks/main.yml
index 6cb195b..7024dca 100644
--- a/roles/combo/tasks/main.yml
+++ b/roles/combo/tasks/main.yml
@@ -1,8 +1,3 @@
-- name: source install django-ckeditor
-  import_tasks: install_source.yml
-  vars:
-    repo: "debian/django-ckeditor"
-    repo_dir: "{{ src_dir }}/django-ckeditor"
 
 - name: source install combo
   import_tasks: install_source.yml
diff --git a/roles/combo/vars/main.yml b/roles/combo/vars/main.yml
index 3d64ad2..3a3636c 100644
--- a/roles/combo/vars/main.yml
+++ b/roles/combo/vars/main.yml
@@ -2,9 +2,10 @@ app_name: combo
 compile_scss: false
 compile_translations: true
 db_name: "{{apps['combo']['db_name']}}"
-manage_cmd: "{{venv_python}} {{src_dir}}/combo/manage.py"
+manage_cmd: "{{venv_py3_python}} {{src_dir}}/combo/manage.py"
 nginx_host_pattern: "{{apps['combo']['nginx_host_pattern']}}"
 nginx_template_name: "std-nginx-server.j2"
 project_name: "{{apps['combo']['project_name']}}"
 server_port: "{{apps['combo']['server_port']}}"
 settings_env_var: COMBO_SETTINGS_FILE
+virtualenv: "{{venv_py3}}"
diff --git a/roles/fargo/vars/main.yml b/roles/fargo/vars/main.yml
index 8177c66..552a390 100644
--- a/roles/fargo/vars/main.yml
+++ b/roles/fargo/vars/main.yml
@@ -8,3 +8,4 @@ nginx_template_name: "fargo-nginx-server.j2"
 project_name: "{{apps['fargo']['project_name']}}"
 server_port: "{{apps['fargo']['server_port']}}"
 settings_env_var: FARGO_SETTINGS_FILE
+virtualenv: "{{venv}}"
diff --git a/roles/hobo/tasks/main.yml b/roles/hobo/tasks/main.yml
index 985712c..98ed2af 100644
--- a/roles/hobo/tasks/main.yml
+++ b/roles/hobo/tasks/main.yml
@@ -1,27 +1,17 @@
 
-- name: source install django-mellon
+- name: source install hobo in python2
   import_tasks: install_source.yml
   vars:
-    repo: "django-mellon"
-    repo_dir: "{{ src_dir }}/django-mellon"
-
-- name: source install gadjo
-  import_tasks: install_source.yml
-  vars:
-    repo: "gadjo"
-    repo_dir: "{{ src_dir }}/gadjo"
-
-- name: source install django-tenant-schemas
-  import_tasks: install_source.yml
-  vars:
-    repo: "debian/django-tenant-schemas"
-    repo_dir: "{{ src_dir }}/django-tenant-schemas"
+    repo: "hobo"
+    repo_dir: "{{ src_dir }}/hobo"
 
-- name: source install hobo
+- name: source install hobo in python3
   import_tasks: install_source.yml
   vars:
     repo: "hobo"
     repo_dir: "{{ src_dir }}/hobo"
+    virtualenv: "{{venv_py3}}"
+
 
 - name: hobo app setup
   import_role:
diff --git a/roles/hobo/vars/main.yml b/roles/hobo/vars/main.yml
index 95bc168..98ec1ac 100644
--- a/roles/hobo/vars/main.yml
+++ b/roles/hobo/vars/main.yml
@@ -8,3 +8,4 @@ nginx_template_name: "std-nginx-server.j2"
 project_name: "{{apps['hobo']['project_name']}}"
 server_port: "{{apps['hobo']['server_port']}}"
 settings_env_var: HOBO_SETTINGS_FILE
+virtualenv: "{{venv}}"
diff --git a/roles/passerelle/tasks/main.yml b/roles/passerelle/tasks/main.yml
index 8fce147..cb9b51a 100644
--- a/roles/passerelle/tasks/main.yml
+++ b/roles/passerelle/tasks/main.yml
@@ -1,10 +1,3 @@
-
-- name: source install django-tenant-schemas
-  import_tasks: install_source.yml
-  vars:
-    repo: "debian/django-tenant-schemas"
-    repo_dir: "{{ src_dir }}/django-tenant-schemas"
-
 - name: source install passerelle
   import_tasks: install_source.yml
   vars:
diff --git a/roles/passerelle/vars/main.yml b/roles/passerelle/vars/main.yml
index 1657b79..8818b4f 100644
--- a/roles/passerelle/vars/main.yml
+++ b/roles/passerelle/vars/main.yml
@@ -8,3 +8,4 @@ nginx_template_name: "std-nginx-server.j2"
 project_name: "{{apps['passerelle']['project_name']}}"
 server_port: "{{apps['passerelle']['server_port']}}"
 settings_env_var: PASSERELLE_SETTINGS_FILE
+virtualenv: "{{venv}}"
diff --git a/roles/wcs/vars/main.yml b/roles/wcs/vars/main.yml
index f811a4c..cc9ddbc 100644
--- a/roles/wcs/vars/main.yml
+++ b/roles/wcs/vars/main.yml
@@ -9,3 +9,4 @@ nginx_template_name: "wcs-nginx-server.j2"
 project_name: "{{apps['wcs']['project_name']}}"
 server_port: "{{apps['wcs']['server_port']}}"
 settings_env_var: WCS_SETTINGS_FILE
+virtualenv: "{{venv}}"
diff --git a/roles/welco/vars/main.yml b/roles/welco/vars/main.yml
index 1092bd7..e8dfa5a 100644
--- a/roles/welco/vars/main.yml
+++ b/roles/welco/vars/main.yml
@@ -8,3 +8,4 @@ nginx_template_name: "welco-nginx-server.j2"
 project_name: "{{apps['welco']['project_name']}}"
 server_port: "{{apps['welco']['server_port']}}"
 settings_env_var: WELCO_SETTINGS_FILE
+virtualenv: "{{venv}}"
-- 
2.20.1

