Python Cheetah - specify name / value pairs for templates

I am trying to configure the Apache httpd template for deployment in different environments, and I would like to use the Cheetah Python application for this. However, I have difficulty with the command line program cheetah, and I consider it a combination of my misunderstanding of Cheetah along with a lack of documentation.

My goal is to have one httpd.conf template file and replace the variables from the environment-specific environment definition file.

httpd.tmpl:

Listen $HTTP_PORT
...
#if $ENABLE_HTTPS == true
<Virtual Host *:$HTTPS_PORT>
    ...
</VirtualHost>
#end if

production.env:

HTTP_PORT=34120
HTTPS_PORT=34121
ENABLE_HTTPS=true

What is the command line needed to populate this Cheetah template? I used:

cheetah f --oext conf --debug httpd

But, obviously, prod.envcannot be read as input file. Adding #includeto the top of my template file:

#include "prod.env"

And none of my names were found:

Cheetah.NameMapper.NotFound: cannot find 'APACHE_PORT'

, , / .

!

EDIT: , python script, , API Cheetah. , .


, @pyfunc, , . --env , . .

+3
1

Cheetah #include Template.

#include raw "prod.env"

#set global $HTTP_PORT="34120"

env , .

, , .

0

Source: https://habr.com/ru/post/1762921/


All Articles