From 3b5b19423f1bdeb09544c8e3f8eafa9897f0762d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Sat, 18 Jan 2020 11:50:24 +0100
Subject: [PATCH] debian: run with python 3 (#39164)

---
 debian/control          | 45 ++++++++++++++++++++---------------------
 debian/debian_config.py |  8 ++++----
 debian/rules            |  8 +++++---
 debian/uwsgi.ini        |  2 +-
 debian/wcs-manage       |  4 ++--
 debian/wcs.triggers     |  2 +-
 setup.py                |  4 ++--
 7 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/debian/control b/debian/control
index d3842b095..27b5cca92 100644
--- a/debian/control
+++ b/debian/control
@@ -2,37 +2,36 @@ Source: wcs
 Section: web
 Priority: optional
 Maintainer: Frederic Peters <fpeters@debian.org>
-Build-Depends: python-quixote, debhelper (>= 9), dh-python, dh-systemd, python-setuptools, gettext, python-gadjo
+Build-Depends: python3-quixote, debhelper (>= 9), python3-all, dh-python, dh-systemd, python3-setuptools, gettext, python3-gadjo
 Standards-Version: 3.9.6.0
 Homepage: https://dev.entrouvert.org/projects/wcs/
-X-Python-Version: 2.7
 
 Package: wcs
 Architecture: all
-Depends: ${misc:Depends}, ${python:Depends},
-    python-django (>= 1.8),
-    python-quixote,
-    python-hobo,
+Depends: ${misc:Depends}, ${python3:Depends},
+    python3-django (>= 1:1.11),
+    python3-quixote,
+    python3-hobo,
     graphviz,
-    python-django-ckeditor,
-    python-django-ratelimit,
-    python-feedparser,
-    python-imaging,
-    python-pyproj,
-    python-requests,
-    python-vobject,
-    python-xstatic-leaflet,
+    python3-django-ckeditor,
+    python3-django-ratelimit,
+    python3-feedparser,
+    python3-imaging,
+    python3-pyproj,
+    python3-requests,
+    python3-vobject,
+    python3-xstatic-leaflet,
     uwsgi,
-    uwsgi-plugin-python
-Recommends: python-dns,
-    python-xlwt,
-    python-qrcode,
-    python-magic,
-    python-docutils,
+    uwsgi-plugin-python3
+Recommends: python3-dns,
+    python3-xlwt,
+    python3-qrcode,
+    python3-magic,
+    python3-docutils,
     poppler-utils
-Suggests: python-libxml2,
-    python-lasso,
-    python-psycopg2
+Suggests: python3-libxml2,
+    python3-lasso,
+    python3-psycopg2
 Description: web application to design and set up online forms
  w.c.s. is a web application which allows to design and set up online forms.
  .
diff --git a/debian/debian_config.py b/debian/debian_config.py
index c8640b1e4..8c327a50e 100644
--- a/debian/debian_config.py
+++ b/debian/debian_config.py
@@ -1,4 +1,4 @@
-# This file is sourced by "execfile" from wcs.settings
+# This file is sourced by "exec(open(..." from wcs.settings
 
 import os
 
@@ -7,7 +7,7 @@ PROJECT_NAME = 'wcs'
 #
 # hobotization
 #
-execfile('/usr/lib/hobo/debian_config_common.py')
+exec(open('/usr/lib/hobo/debian_config_common.py').read())
 
 # and some hobo parts that are specific to w.c.s.
 TEMPLATES[0]['OPTIONS']['context_processors'] = [
@@ -40,7 +40,7 @@ LOGGING = {}
 #
 # local settings
 #
-execfile(os.path.join(ETC_DIR, 'settings.py'))
+exec(open(os.path.join(ETC_DIR, 'settings.py')).read())
 
 # run additional settings snippets
-execfile('/usr/lib/hobo/debian_config_settings_d.py')
+exec(open('/usr/lib/hobo/debian_config_settings_d.py').read())
diff --git a/debian/rules b/debian/rules
index e3fc3c1aa..3d48476ae 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,11 +1,10 @@
 #!/usr/bin/make -f
 # GNU copyright 1997 to 1999 by Joey Hess.
 
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
+export PYBUILD_NAME=wcs
 
 %:
-	dh $@ --with python2,systemd
+	dh $@ --with python3,systemd --buildsystem=pybuild
 
 override_dh_install:
 	dh_install
@@ -15,3 +14,6 @@ override_dh_install:
 		$(CURDIR)/debian/wcs/usr/lib/wcs/
 	install -d $(CURDIR)/debian/wcs/etc/wcs
 	install -m 644 wcs.cfg-sample $(CURDIR)/debian/wcs/etc/wcs/wcs.cfg
+
+override_dh_auto_test:
+	# skip upstream tests
diff --git a/debian/uwsgi.ini b/debian/uwsgi.ini
index cb7e73d1a..06d336476 100644
--- a/debian/uwsgi.ini
+++ b/debian/uwsgi.ini
@@ -2,7 +2,7 @@
 auto-procname = true
 procname-prefix-spaced = wcs
 
-plugin = python
+plugin = python3
 module = wcs.wsgi:application
 
 http-socket = /run/wcs/wcs.sock
diff --git a/debian/wcs-manage b/debian/wcs-manage
index 18f2bf8af..067e9a6f3 100755
--- a/debian/wcs-manage
+++ b/debian/wcs-manage
@@ -18,8 +18,8 @@ fi
 
 if test $# -eq 0
 then
-    python ${MANAGE} help
+    python3 ${MANAGE} help
     exit 1
 fi
 
-python ${MANAGE} "$@"
+python3 ${MANAGE} "$@"
diff --git a/debian/wcs.triggers b/debian/wcs.triggers
index 295ead96b..c0559ec49 100644
--- a/debian/wcs.triggers
+++ b/debian/wcs.triggers
@@ -1,2 +1,2 @@
 interest-noawait hobo-redeploy
-interest-noawait /usr/lib/python2.7/dist-packages/gadjo/static
+interest-noawait /usr/lib/python3/dist-packages/gadjo/static
diff --git a/setup.py b/setup.py
index 9af47e08f..ad04c08c0 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ from setuptools import setup, find_packages
 
 local_cfg = None
 if os.path.exists('wcs/wcs_cfg.py'):
-    local_cfg = file('wcs/wcs_cfg.py').read()
+    local_cfg = open('wcs/wcs_cfg.py').read()
     os.unlink('wcs/wcs_cfg.py')
 
 
@@ -138,4 +138,4 @@ setup(
     )
 
 if local_cfg:
-    file('wcs/wcs_cfg.py', 'w').write(local_cfg)
+    open('wcs/wcs_cfg.py', 'w').write(local_cfg)
-- 
2.25.0

