Package: eztemplate
Simple templating program to generate plain text (like config files)
from name-value pairs.Lets you create text files from templates in a versatile way. It’s
designed with easy operation from the command line or scripts,
Makefiles, etc. in mind. You can make use of several third party
templating engines likemakoorempyas well as simple built-in
ones.Installationfrom PyPI into a virtualenv (recommended)Withvirtualenvyou create a separate python environment without
affecting the rest of your system, therefore this approach is
recommended for playing around.Install virtualenvon Debian-based distributions (such as Ubuntu)$sudoapt-getinstallvirtualenvon Fedora$sudoyuminstallpython-virtualenvInstall eztemplate$virtualenvmyvenv# create a new environment in a subdirectory$.myvenv/bin/activate# switch to virtualenv (important)$pipinstalleztemplate# install eztemplate from PyPI$eztemplate--version# check if the correct version was installedUpgrade eztemplate$.myvenv/bin/activate# switch to virtualenv (if not there already)$pipinstall--upgradeeztemplate# upgrade eztemplate from PyPI$eztemplate--version# check if the corrent version was installedfrom a git repository into a virtualenvThis is a good approach if you work on the repository and want to test
the changes.Install eztemplate$gitclonehttps://github.com/blubberdiblub/eztemplate.git$cdeztemplate# change into the cloned repository$virtualenvvenv# create a new environment in a subdirectory$.venv/bin/activate# switch to virtualenv (important)$pipinstall.# just specify the directory to install from$eztemplate--version# check if the correct version was installedUpgrade eztemplate$gitpull# pull latest commits from remote repository$.venv/bin/activate# switch to virtualenv (if not there already)$pipinstall--upgrade--force-reinstall.# force upgrade eztemplate$eztemplate--version# check if the correct version was installedfrom PyPI as system commandInstall eztemplate$pipinstalleztemplate# install eztemplate from PyPI$eztemplate--version# check if the correct version was installedUpgrade eztemplate$pipinstall--upgradeeztemplate# upgrade eztemplate from PyPI$eztemplate--version# check if the corrent version was installedUsageGetting quick helpUse the help option:$eztemplate--helpYou can also call the package explictly with Python (and thereby choose
which Python installation to use):$python-meztemplate--helpRunning without argumentsWhen you runeztemplatewithout arguments, it will expect a template
on standard input, possibly waiting forever:$eztemplateHello,world!<Ctrl-D>Hello,world!$On __*ix__ terminals you can manually cause an end of file by
pressingCtrl-D.Quick demonstrationYou can check that substitution is working by piping a template into the
program and specifying a name-value pair (make sure to protect the
string with single quotes, otherwise the shell believes you want to
substitute a shell variable, replacing it by an empty string):$echo'Hello, $entity.'|eztemplateentity=worldHello,world.$When you’re callingeztemplatefrom a script or similar - i. e.
non-interactively - you should specify everything as explicitly as
possible (in particular all input files orstdinas well as name-value
pairs) and refrain from using positional arguments. Everything can be
specified using options, which avoids ambiguities:$echo'Hello, $entity.'|eztemplate--stdin--argentity=worldHello,world.$Templating engineseztemplatesupports several templating engines. You select the one
you want to use with the-eor--engineoption. Specifyinghelpinstead of a name will list all currently available engines:$eztemplate-ehelpAvailabletemplatingengines:empy-Empytemplatingengine.mako-Makotemplatingengine.string.Template-String.Templateengine.$Engines missing the required packages, modules or libraries will not be
displayed. For instance to be able to use themakoor theempyengine, you need to have the respective python packages installed and
working.However,eztemplatecomes with simple built-in engines which are
available at all times. Thestring.Templateengine is the default
when you don’t explicitly specify one.string.Template engineThis engine is named after thestring.Template
classin the Python standard library. It substitutes identifiers beginning
with a dollar sign. To resolve ambiguities, you can also enclose the
identifier in curly braces. It’s similar to shell variable subsitution
minus the more sophisticated features. It suffices for simple cases
where you just need to insert some values into a text:$eztemplate--stdin\>--arguser="$(getentpasswd"$USER"|cut-d:-f5|cut-d,-f1)"\>--argfood=cake--argvendor=cafeteria--argprice="$RANDOM"\><<\EOF
> Hello, $user.
>
> If you're hungry, get some ${food}s from the $vendor.
> They're only $$$price per piece.
> EOFHello,NielsBoehm.Ifyou're hungry, get some cakes from the cafeteria.
They'reonly$29993perpiece.$