From bac15c89397dbeb2329ea2f978fee029b34cbfad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Mon, 13 Apr 2020 13:49:38 +0200
Subject: [PATCH] debian: run hobo & hobo-agent with python 3 (#41640)

---
 debian/agent/hobo-agent.conf                  |  2 +-
 debian/control                                | 21 +++++++++++--------
 ...thon-hobo.install => python3-hobo.install} |  0
 debian/rules                                  |  4 ++--
 debian/server/debian_config.py                |  8 +++----
 debian/server/hobo-manage                     |  5 ++---
 debian/server/uwsgi.ini                       |  2 +-
 manage.py                                     |  2 +-
 8 files changed, 23 insertions(+), 21 deletions(-)
 rename debian/{python-hobo.install => python3-hobo.install} (100%)

diff --git a/debian/agent/hobo-agent.conf b/debian/agent/hobo-agent.conf
index 66a96cf..c09441d 100644
--- a/debian/agent/hobo-agent.conf
+++ b/debian/agent/hobo-agent.conf
@@ -1,6 +1,6 @@
 [program:hobo-agent]
 ; Concurrency set to 1 because there is no lock around calls to hobo_notify
-command=python2.7 /usr/bin/celery worker --hostname=agent.%%h --app=hobo.agent.worker --loglevel=INFO --concurrency=1 --maxtasksperchild=100
+command=python3 /usr/bin/celery worker --hostname=agent.%%h --app=hobo.agent.worker --loglevel=INFO --concurrency=1 --maxtasksperchild=100
 environment=HOBO_AGENT_SETTINGS_FILE="/etc/hobo-agent/settings.py"
 process_name=hobo-agent
 user=hobo-agent
diff --git a/debian/control b/debian/control
index b319cb7..a2c7786 100644
--- a/debian/control
+++ b/debian/control
@@ -9,6 +9,7 @@ Package: python-hobo
 Architecture: all
 Depends: ${misc:Depends},
     ${python:Depends},
+    python3-hobo (= ${binary:Version}),
     python-django (>= 1:1.11),
     python-celery (>= 3.1.13),
     python-requests,
@@ -37,6 +38,8 @@ Depends: ${misc:Depends},
     python3-djangorestframework,
     python3-dnspython,
     python3-systemd
+Breaks: python-hobo (<< 1.51.post2)
+Replaces: python-hobo (<< 1.51.post2)
 Recommends:
     python3-gadjo,
     python3-django-mellon (>= 1.2.22.26),
@@ -45,14 +48,14 @@ Description: Rapid Remote Deployment python 3 module
 
 Package: hobo
 Architecture: all
-Depends: python-hobo (= ${binary:Version}),
-    python-django-tenant-schemas,
-    python-psycopg2,
-    python-django (>= 1.8),
-    python-gadjo,
-    python-django-mellon (>= 1.2.17),
+Depends: python3-hobo (= ${binary:Version}),
+    python3-django-tenant-schemas,
+    python3-psycopg2,
+    python3-django (>= 1.8),
+    python3-gadjo,
+    python3-django-mellon (>= 1.2.17),
     uwsgi,
-    uwsgi-plugin-python
+    uwsgi-plugin-python3
 Recommends: nginx,
     rabbitmq-server (>= 3.3),
     erlang-nox (>= 1:17.1)
@@ -61,8 +64,8 @@ Description:  Rapid Remote Deployment Daemon
 
 Package: hobo-agent
 Architecture: all
-Depends: python-hobo (= ${binary:Version}),
-    python-celery-common,
+Depends: python3-hobo (= ${binary:Version}),
+    python3-celery-common,
     sudo,
     supervisor
 Description: Rapid Remote Deployment Agent
diff --git a/debian/python-hobo.install b/debian/python3-hobo.install
similarity index 100%
rename from debian/python-hobo.install
rename to debian/python3-hobo.install
diff --git a/debian/rules b/debian/rules
index d3f824f..f59e4e1 100755
--- a/debian/rules
+++ b/debian/rules
@@ -12,5 +12,5 @@ PYTHON3_HOBO_DIR=$(CURDIR)/debian/python3-hobo
 
 override_dh_install:
 	dh_install
-	mv $(PYTHON_HOBO_DIR)/usr/bin/manage.py $(PYTHON_HOBO_DIR)/usr/lib/hobo/manage.py
-	rm $(PYTHON3_HOBO_DIR)/usr/bin/manage.py
+	mv $(PYTHON3_HOBO_DIR)/usr/bin/manage.py $(PYTHON3_HOBO_DIR)/usr/lib/hobo/manage.py
+	rm $(PYTHON_HOBO_DIR)/usr/bin/manage.py
diff --git a/debian/server/debian_config.py b/debian/server/debian_config.py
index 2d7e46e..9c8e83b 100644
--- a/debian/server/debian_config.py
+++ b/debian/server/debian_config.py
@@ -1,9 +1,9 @@
-# This file is sourced by "execfile" from hobo.settings
+# This file is sourced by "exec" from hobo.settings
 
 import os
 
 PROJECT_NAME = 'hobo'
-execfile('/usr/lib/hobo/debian_config_common.py')
+exec(open('/usr/lib/hobo/debian_config_common.py').read())
 
 # hobo don't use multitenant mellon adapter: IdP is detected in the local
 # environnment
@@ -13,7 +13,7 @@ MELLON_ADD_AUTHNREQUEST_NEXT_URL_EXTENSION = True
 # add custom hobo agent module
 INSTALLED_APPS = ('hobo.agent.hobo', ) + INSTALLED_APPS
 
-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/server/hobo-manage b/debian/server/hobo-manage
index 743dc71..8f17c81 100755
--- a/debian/server/hobo-manage
+++ b/debian/server/hobo-manage
@@ -18,9 +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/server/uwsgi.ini b/debian/server/uwsgi.ini
index ff607a2..ba422ef 100644
--- a/debian/server/uwsgi.ini
+++ b/debian/server/uwsgi.ini
@@ -2,7 +2,7 @@
 auto-procname = true
 procname-prefix-spaced = hobo
 
-plugin = python
+plugin = python3
 module = hobo.wsgi:application
 
 http-socket = /run/hobo/hobo.sock
diff --git a/manage.py b/manage.py
index c84d3a0..6206835 100755
--- a/manage.py
+++ b/manage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import os
 import sys
 
-- 
2.26.0

