From 71ad011d8eefefdfcc0355012865ba3478ed688c Mon Sep 17 00:00:00 2001
From: Benjamin Dauvergne <bdauvergne@entrouvert.com>
Date: Sun, 1 Mar 2020 12:11:17 +0100
Subject: [PATCH 1/2] python3: adapt debian packaging (#40372)

---
 debian/authentic2-multitenant.init            |  2 +-
 debian/authentic2-multitenant.service         |  2 +-
 debian/authentic2.init                        |  4 +-
 debian/control                                | 82 +++++++++----------
 .../multitenant/authentic2-multitenant-manage |  2 +-
 debian/py3dist-overrides                      | 17 ++++
 debian/pydist-overrides                       | 14 ----
 ...uthentic2.dirs => python3-authentic2.dirs} |  0
 ...uthentic2.docs => python3-authentic2.docs} |  0
 ...ic2.install => python3-authentic2.install} |  0
 debian/rules                                  |  8 +-
 11 files changed, 66 insertions(+), 65 deletions(-)
 create mode 100644 debian/py3dist-overrides
 delete mode 100644 debian/pydist-overrides
 rename debian/{python-authentic2.dirs => python3-authentic2.dirs} (100%)
 rename debian/{python-authentic2.docs => python3-authentic2.docs} (100%)
 rename debian/{python-authentic2.install => python3-authentic2.install} (100%)

diff --git a/debian/authentic2-multitenant.init b/debian/authentic2-multitenant.init
index 9c6b7b745..821ae80cc 100644
--- a/debian/authentic2-multitenant.init
+++ b/debian/authentic2-multitenant.init
@@ -16,7 +16,7 @@
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC=authentic2
 NAME=authentic2-multitenant
-DAEMON=/usr/bin/gunicorn
+DAEMON=/usr/bin/gunicorn3
 PID_DIR=/var/run/$NAME
 CACHE_DIR=/var/cache/$NAME
 LOG_DIR=/var/log/$NAME
diff --git a/debian/authentic2-multitenant.service b/debian/authentic2-multitenant.service
index 723e8240e..0af8969ca 100644
--- a/debian/authentic2-multitenant.service
+++ b/debian/authentic2-multitenant.service
@@ -10,7 +10,7 @@ User=authentic-multitenant
 Group=authentic-multitenant
 ExecStartPre=/usr/bin/authentic2-multitenant-manage migrate_schemas --noinput
 ExecStartPre=/usr/bin/authentic2-multitenant-manage collectstatic --noinput
-ExecStart=/usr/bin/gunicorn \
+ExecStart=/usr/bin/gunicorn3 \
           --bind unix:/run/%p/%p.sock \
           --worker-class=sync \
           --workers 5 \
diff --git a/debian/authentic2.init b/debian/authentic2.init
index cd7645ee2..724857f4b 100644
--- a/debian/authentic2.init
+++ b/debian/authentic2.init
@@ -16,7 +16,7 @@
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC=authentic2
 NAME=authentic2
-DAEMON=/usr/bin/gunicorn
+DAEMON=/usr/bin/gunicorn3
 PID_DIR=/var/run/$NAME
 CACHE_DIR=/var/cache/$NAME
 LOG_DIR=/var/log/$NAME
@@ -129,7 +129,7 @@ do_reload() {
 
 do_migrate() {
     log_action_msg "Applying new migrations .."
-    VERSION=`dpkg-query --show --showformat '${Version}' python-django`
+    VERSION=`dpkg-query --show --showformat '${Version}' python3-django`
     if dpkg --compare-versions $VERSION lt 1.7; then
       su $USER -p -c "$MANAGE_SCRIPT syncdb --migrate --noinput"
     else
diff --git a/debian/control b/debian/control
index cc32bd0b5..cda487f84 100644
--- a/debian/control
+++ b/debian/control
@@ -2,45 +2,41 @@ Source: authentic2
 Section: python
 Priority: optional
 Maintainer: Jerome Schneider <jschneider@entrouvert.com>
-Build-Depends-Indep: python-all-dev (>= 2.6)
-Build-Depends: debhelper (>= 9.0), python-setuptools, python-django (>= 1.5), dh-python, dh-systemd
-Standards-Version: 3.8.3
+Build-Depends-Indep: python3-all-dev
+Build-Depends: debhelper (>= 9), dh-python, dh-systemd, python3-setuptools, python3-django
+Standards-Version: 3.9.6
 Homepage: http://authentic.labs.libre-entreprise.org
-X-Python-Version: >= 2.7
 
-Package: python-authentic2
+Package: python3-authentic2
 Architecture: all
 Depends: ${misc:Depends}, ${python:Depends},
-    python-django (>= 1:1.11),
+    python3-django (>= 1:1.11),
     openssl,
-    python-requests (>=2.3),
-    python-django-model-utils (>= 2.4),
-    python-lasso (>= 2.4.1.100),
-    python-dnspython (>= 1.10),
-    python-django-select2 (>= 5),
-    python-gadjo (>= 0.53),
-    python-django-tables2 (>= 1),
-    python-django-import-export (>= 1),
-    python-django-import-export (< 2),
-    python-djangorestframework (>= 3.3),
-    python-markdown (>= 2.1),
-    python-ldap (>= 2.4),
-    python-six (>= 1.0),
-    python-jwcrypto (>= 0.3.1),
-    python-cryptography (>= 1.3.4),
-    python-django-filters (>= 1),
-    python-django-filters (<< 2),
-    python-pil,
-    python-tablib,
-    python-chardet,
-    python-attr (>=17),
-    python-pycryptodome,
-    python-atomicwrites
-Breaks: python-authentic2-auth-fc (<< 0.26)
-Replaces: python-authentic2-auth-fc (<< 0.26)
-Provides: ${python:Provides}, python-authentic2-auth-fc
-Recommends: python-ldap
-Suggests: python-raven
+    python3-requests (>=2.3),
+    python3-requests-oauthlib,
+    python3-django-model-utils (>= 2.4),
+    python3-lasso (>= 2.4.1.100),
+    python3-dnspython (>= 1.10),
+    python3-django-select2 (>= 5),
+    python3-gadjo (>= 0.53),
+    python3-django-tables2 (>= 1),
+    python3-django-import-export (>= 1),
+    python3-django-import-export (< 2),
+    python3-djangorestframework (>= 3.3),
+    python3-django-ratelimit,
+    python3-markdown (>= 2.1),
+    python3-ldap (>= 2.4),
+    python3-six (>= 1.0),
+    python3-jwcrypto (>= 0.3.1),
+    python3-cryptography (>= 1.3.4),
+    python3-django-filters (>= 1),
+    python3-django-filters (<< 2),
+    python3-pil,
+    python3-tablib,
+    python3-chardet,
+    python3-attr (>=17),
+    python3-pycryptodome,
+    python3-atomicwrites
 Description: Versatile identity server
  Authentic is a versatile identity provider aiming to address a broad
  range of needs, from simple to complex setups; it has support for many
@@ -52,9 +48,9 @@ Description: Versatile identity server
 Package: authentic2
 Architecture: all
 Depends: ${misc:Depends}, adduser,
-    python-authentic2 (= ${binary:Version}),
-    python-psycopg2,
-    gunicorn, dbconfig-common,
+    python3-authentic2 (= ${binary:Version}),
+    python3-psycopg2,
+    gunicorn3, dbconfig-common,
     debconf | debconf-2.0, ucf
 Recommends: postgresql-client
 Suggests: nginx, postgresql
@@ -69,12 +65,12 @@ Description: Versatile identity server Python module
 Package: authentic2-multitenant
 Architecture: all
 Depends: ${misc:Depends}, adduser,
-    python-authentic2 (= ${binary:Version}),
-    python-psycopg2,
-    python-django-tenant-schemas (>= 1.5.2.1),
-    python-hobo,
-    python-jwcrypto (>= 0.4.2),
-    gunicorn, dbconfig-common,
+    python3-authentic2 (= ${binary:Version}),
+    python3-psycopg2,
+    python3-django-tenant-schemas (>= 1.5.2.1),
+    python3-hobo,
+    python3-jwcrypto (>= 0.4.2),
+    gunicorn3, dbconfig-common,
     debconf | debconf-2.0, ucf
 Recommends: postgresql-client
 Suggests: nginx, postgresql
diff --git a/debian/multitenant/authentic2-multitenant-manage b/debian/multitenant/authentic2-multitenant-manage
index 6730481c0..975e9805a 100644
--- a/debian/multitenant/authentic2-multitenant-manage
+++ b/debian/multitenant/authentic2-multitenant-manage
@@ -16,4 +16,4 @@ if [ "$(whoami)" != "authentic-multitenant" ]; then
     fi
 fi
 
-python ${MANAGE} "$@"
+python3 ${MANAGE} "$@"
diff --git a/debian/py3dist-overrides b/debian/py3dist-overrides
new file mode 100644
index 000000000..08e7cbbe0
--- /dev/null
+++ b/debian/py3dist-overrides
@@ -0,0 +1,17 @@
+django                  python3-django
+requests                python3-requests
+django-model-utils      python3-django-model-utils
+dnspython               python3-dnspython
+django-select2          python3-django-select2
+django-tables           python3-django-tables2
+gadjo                   python3-gadjo
+XStatic_jQuery          python3-xstatic-jquery
+XStatic_jquery_ui       python3-xstatic-jquery-ui
+django-import-export    python3-django-import-export
+django-sekizai          python3-django-sekizai
+six                     python3-six
+pycryptodome            python3-pycryptodome
+ldaptools               python3-ldaptools
+django-mellon           python3-django-mellon
+django-ratelimit        python3-django-ratelimit
+requests-oauthlib       python3-requests-oauthlib
diff --git a/debian/pydist-overrides b/debian/pydist-overrides
deleted file mode 100644
index f1f7f3421..000000000
--- a/debian/pydist-overrides
+++ /dev/null
@@ -1,14 +0,0 @@
-django                  python-django
-requests                python-requests
-django-model-utils      python-django-model-utils
-dnspython               python-dnspython
-django-select2          python-django-select2
-django-tables           python-django-tables2
-gadjo                   python-gadjo
-XStatic_jQuery          python-xstatic-jquery
-XStatic_jquery_ui       python-xstatic-jquery-ui
-django-import-export    python-django-import-export
-six                     python-six
-pycryptodome            python-pycryptodome
-ldaptools               python-ldaptools
-django-mellon           python-django-mellon
diff --git a/debian/python-authentic2.dirs b/debian/python3-authentic2.dirs
similarity index 100%
rename from debian/python-authentic2.dirs
rename to debian/python3-authentic2.dirs
diff --git a/debian/python-authentic2.docs b/debian/python3-authentic2.docs
similarity index 100%
rename from debian/python-authentic2.docs
rename to debian/python3-authentic2.docs
diff --git a/debian/python-authentic2.install b/debian/python3-authentic2.install
similarity index 100%
rename from debian/python-authentic2.install
rename to debian/python3-authentic2.install
diff --git a/debian/rules b/debian/rules
index be98d8843..b57dcee30 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,12 +1,14 @@
 #!/usr/bin/make -f
 
+export PYBUILD_DISABLE=test
+
 authentic2=$(CURDIR)/debian/authentic2
-pythonauthentic2=$(CURDIR)/debian/python-authentic2
+python3authentic2=$(CURDIR)/debian/python3-authentic2
 
 %:
-	dh $@ --with python2,systemd
+	dh $@ --with python3,systemd --buildsystem=pybuild
 
 override_dh_install:
 	dh_install
-	mv $(CURDIR)/debian/tmp/usr/bin/authentic2-ctl $(pythonauthentic2)/usr/lib/authentic2/manage.py
+	mv $(CURDIR)/debian/tmp/usr/bin/authentic2-ctl $(python3authentic2)/usr/lib/authentic2/manage.py
 
-- 
2.26.0

