From 844b35589e31deec76cd997567e43a4262d28c80 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 10 May 2018 01:14:53 +0200 Subject: [PATCH 1/2] Add ynh_render_template helper to render templates with jinja2 --- data/helpers.d/utils | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/data/helpers.d/utils b/data/helpers.d/utils index cc057eb0b..05f9a4703 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -234,3 +234,20 @@ ynh_local_curl () { # Curl the URL curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url" } + +# Render templates with Jinja2 +# +# Attention : Variables should be exported before calling this helper to be +# accessible inside templates. +# +# usage: ynh_render_template some_template output_path +# | arg: some_template - Template file to be rendered +# | arg: output_path - The path where the output will be redirected to +ynh_render_template() { + local template_path=$1 + local output_path=$2 + # Taken from https://stackoverflow.com/a/35009576 + python2.7 -c 'import os, sys, jinja2; sys.stdout.write( + jinja2.Template(sys.stdin.read() + ).render(os.environ));' < $template_path > $output_path +} From 890eb7a885ef7b2df7611dee3fe1cdd1b75b2b9b Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 10 May 2018 01:29:03 +0200 Subject: [PATCH 2/2] Add dependency to python-jinja2 --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index d1505994a..d069dc678 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ Architecture: all Depends: ${python:Depends}, ${misc:Depends} , moulinette (>= 2.7.1), ssowat (>= 2.7.1) , python-psutil, python-requests, python-dnspython, python-openssl - , python-apt, python-miniupnpc + , python-apt, python-miniupnpc, python-jinja2 , glances , dnsutils, bind9utils, unzip, git, curl, cron, wget , ca-certificates, netcat-openbsd, iproute