From ac20415e4ac7d07a7947591ef06bfedfdc40c627 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Mon, 6 Apr 2020 10:23:24 +0200
Subject: [PATCH] build: switch everything to Python 3 (#41347)

---
 Makefile                      | 30 +++++++++++++++---------------
 debian/control                |  2 +-
 get_themes.py                 |  4 ++--
 make_data_uris.py             |  6 +++---
 src/render-imgs-categories.py |  2 +-
 src/render-imgs-dashboard.py  |  2 +-
 6 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile
index c6b10107..a0184eab 100644
--- a/Makefile
+++ b/Makefile
@@ -6,19 +6,19 @@ prefix = /usr
 all: themes.json icons css
 
 static/includes/_data_uris.scss: $(wildcard static/includes/img/*)
-	python make_data_uris.py static/includes/
+	python3 make_data_uris.py static/includes/
 
 static/toodego/_data_uris.scss: $(wildcard static/toodego/img/*)
-	python make_data_uris.py static/toodego/
+	python3 make_data_uris.py static/toodego/
 
 static/lille/_data_uris.scss: $(wildcard static/lille/img/*)
-	python make_data_uris.py static/lille/
+	python3 make_data_uris.py static/lille/
 
 static/lomme/_data_uris.scss: $(wildcard static/lomme/img/*)
-	python make_data_uris.py static/lomme/
+	python3 make_data_uris.py static/lomme/
 
 static/hellemmes/_data_uris.scss: $(wildcard static/hellemmes/img/*)
-	python make_data_uris.py static/hellemmes/
+	python3 make_data_uris.py static/hellemmes/
 
 themes.json: $(wildcard static/*/config.json) help/fr/misc-scss.page
 	python3 create_themes_json.py
@@ -28,23 +28,23 @@ themes.json: $(wildcard static/*/config.json) help/fr/misc-scss.page
 %.css: %.scss $(wildcard static/includes/*.scss  static/includes/*/*.scss) static/includes/_data_uris.scss static/lille/_data_uris.scss static/lomme/_data_uris.scss static/hellemmes/_data_uris.scss static/toodego/_data_uris.scss $$(wildcard $$(@D)/*.scss)
 	sassc --sourcemap $< $@
 
-css: $(shell python get_themes.py) static/portal-agent/css/agent-portal.css
+css: $(shell python3 get_themes.py) static/portal-agent/css/agent-portal.css
 	rm -rf static/*/.sass-cache/
 
 icons:
 	# chateauroux
-	cd src/ && python render-imgs-dashboard.py ../static/chateauroux/img/ --normal 333333 --selected 0779B7 --title FFFFFF --title-width 80
+	cd src/ && python3 render-imgs-dashboard.py ../static/chateauroux/img/ --normal 333333 --selected 0779B7 --title FFFFFF --title-width 80
 	# orleans
-	cd src/ && python render-imgs-categories.py ../static/orleans/img/ --primary f05923 --secondary 34697D
-	cd src/ && python render-imgs-dashboard.py ../static/orleans/img/ --normal FFFFFF --normal-width 30 --selected f05923 --selected-width 30 --title FFFFFF --title-width 80
+	cd src/ && python3 render-imgs-categories.py ../static/orleans/img/ --primary f05923 --secondary 34697D
+	cd src/ && python3 render-imgs-dashboard.py ../static/orleans/img/ --normal FFFFFF --normal-width 30 --selected f05923 --selected-width 30 --title FFFFFF --title-width 80
 	# publik
-	cd src/ && python render-imgs-categories.py ../static/publik/img/
-	cd src/ && python render-imgs-dashboard.py ../static/publik/img/ --normal 4D4D4D --selected DF017A --title FFFFFF --title-width 80
+	cd src/ && python3 render-imgs-categories.py ../static/publik/img/
+	cd src/ && python3 render-imgs-dashboard.py ../static/publik/img/ --normal 4D4D4D --selected DF017A --title FFFFFF --title-width 80
 	# somme
-	cd src/ && python render-imgs-categories.py ../static/somme-cd80/img/ --primary A8002B --secondary A8002B
-	cd src/ && python render-imgs-dashboard.py ../static/somme-cd80/img/ --normal 4D4D4D --selected 87A738 --title FFFFFF --title-width 80
-	cd src/ && python render-imgs-categories.py ../static/hautes-alpes-2018/img/icon-rouge --primary B73720 --secondary B73720
-	cd src/ && python render-imgs-categories.py ../static/hautes-alpes-2018/img/icon-bleu --primary 1C515E --secondary 1C515E
+	cd src/ && python3 render-imgs-categories.py ../static/somme-cd80/img/ --primary A8002B --secondary A8002B
+	cd src/ && python3 render-imgs-dashboard.py ../static/somme-cd80/img/ --normal 4D4D4D --selected 87A738 --title FFFFFF --title-width 80
+	cd src/ && python3 render-imgs-categories.py ../static/hautes-alpes-2018/img/icon-rouge --primary B73720 --secondary B73720
+	cd src/ && python3 render-imgs-categories.py ../static/hautes-alpes-2018/img/icon-bleu --primary 1C515E --secondary 1C515E
 	# tournai
 	cd static/tournai/ && for F in assets/*.svg; do inkscape --without-gui --file $$F --export-area-drawing --export-area-snap --export-png img/$$(basename $$F .svg).png --export-width 40; done
 
diff --git a/debian/control b/debian/control
index fa619516..03e02f1e 100644
--- a/debian/control
+++ b/debian/control
@@ -8,7 +8,7 @@ Homepage: http://git.entrouvert.org/publik-base-theme.git
 
 Package: publik-base-theme
 Architecture: all
-Depends: ${shlibs:Depends}, ${misc:Depends}, python-gadjo
+Depends: ${shlibs:Depends}, ${misc:Depends}, python-gadjo, python3-gadjo
 Conflicts: python-authentic2 (< 2.1.20.742.gb6ee096-0),
            python-django (<= 1:1.11),
            python-xstatic-roboto-fontface (< 0.5.0.0),
diff --git a/get_themes.py b/get_themes.py
index aa64164f..c99ea79e 100644
--- a/get_themes.py
+++ b/get_themes.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 import os
 
@@ -6,4 +6,4 @@ for dirname in sorted(os.listdir('static')):
     config = os.path.join('static', dirname, 'config.json')
     if not os.path.exists(config):
         continue
-    print 'static/%s/style.css' % dirname
+    print('static/%s/style.css' % dirname)
diff --git a/make_data_uris.py b/make_data_uris.py
index 84803f83..a0e72ecf 100644
--- a/make_data_uris.py
+++ b/make_data_uris.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 import base64
 import os
@@ -18,8 +18,8 @@ for filename in os.listdir('img/'):
     filesize = os.stat('img/' + filename).st_size
     if filesize > 10000:
         continue
-    filecontent = open('img/' + filename).read()
-    b64 = base64.encodestring(filecontent).replace('\n', '')
+    filecontent = open('img/' + filename, 'rb').read()
+    b64 = base64.encodebytes(filecontent).decode('ascii').replace('\n', '')
     data_uris.append('$data_uri_%(varname)s: "data:%(mimetype)s;base64,%(b64)s" !default;' % locals())
 
 open('_data_uris.scss', 'w').write('\n'.join(data_uris))
diff --git a/src/render-imgs-categories.py b/src/render-imgs-categories.py
index 5de4954e..216c3317 100644
--- a/src/render-imgs-categories.py
+++ b/src/render-imgs-categories.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 # publik-base-theme
 # Copyright (C) 2016  Entr'ouvert
diff --git a/src/render-imgs-dashboard.py b/src/render-imgs-dashboard.py
index cbd1f3da..3bc26a06 100644
--- a/src/render-imgs-dashboard.py
+++ b/src/render-imgs-dashboard.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 
 # publik-base-theme
 # Copyright (C) 2016  Entr'ouvert
-- 
2.26.0

