Skip to main content

Simple templating program to generate plain text (like config files) from name-value pairs.

Project description

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 like mako or empy as well as simple built-in ones.

Installation

from a git repository into a virtualenv

This is a good approach if you work on the repository and want to test the changes.

Install eztemplate

$ git clone https://github.com/blubberdiblub/eztemplate.git
$ cd eztemplate                    # change into the cloned repository
$ virtualenv venv                  # create a new environment in a subdirectory
$ . venv/bin/activate              # switch to virtualenv (important)
$ pip install .                    # just specify the directory to install from
$ eztemplate --version             # check if the correct version was installed

Upgrade eztemplate

$ git pull                         # pull latest commits from remote repository
$ . venv/bin/activate              # switch to virtualenv (if not there already)
$ pip install --upgrade --force-reinstall . # force upgrade eztemplate
$ eztemplate --version             # check if the correct version was installed

from PyPI as system command

Install eztemplate

$ pip install eztemplate           # install eztemplate from PyPI
$ eztemplate --version             # check if the correct version was installed

Upgrade eztemplate

$ pip install --upgrade eztemplate # upgrade eztemplate from PyPI
$ eztemplate --version             # check if the corrent version was installed

Usage

Getting quick help

Use the help option:

$ eztemplate --help

You can also call the package explictly with Python (and thereby choose which Python installation to use):

$ python -m eztemplate --help

Running without arguments

When you run eztemplate without arguments, it will expect a template on standard input, possibly waiting forever:

$ eztemplate
Hello, world!
<Ctrl-D>
Hello, world!
$

On __*ix__ terminals you can manually cause an end of file by pressing Ctrl-D.

Quick demonstration

You 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.' | eztemplate entity=world
Hello, world.
$

When you’re calling eztemplate from a script or similar - i. e. non-interactively - you should specify everything as explicitly as possible (in particular all input files or stdin as 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 --arg entity=world
Hello, world.
$

Templating engines

eztemplate supports several templating engines. You select the one you want to use with the -e or --engine option. Specifying help instead of a name will list all currently available engines:

$ eztemplate -e help
Available templating engines:
  empy             -  Empy templating engine.
  mako             -  Mako templating engine.
  string.Template  -  String.Template engine.
$

Engines missing the required packages, modules or libraries will not be displayed. For instance to be able to use the mako or the empy engine, you need to have the respective python packages installed and working.

However, eztemplate comes with simple built-in engines which are available at all times. The string.Template engine is the default when you don’t explicitly specify one.

string.Template engine

This engine is named after the string.Template class in 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 \
>   --arg user="$( getent passwd "$USER" | cut -d: -f5 | cut -d, -f1 )" \
>   --arg food=cake --arg vendor=cafeteria --arg price="$RANDOM" \
>   <<\EOF
> Hello, $user.
>
> If you're hungry, get some ${food}s from the $vendor.
> They're only $$$price per piece.
> EOF
Hello, Niels Boehm.

If you're hungry, get some cakes from the cafeteria.
They're only $29993 per piece.
$

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

eztemplate-0.3.0.tar.gz (15.4 kB view details)

Uploaded Source

eztemplate-0.3.0.linux-x86_64.tar.gz (19.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

eztemplate-0.3.0-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

eztemplate-0.3.0-py2-none-any.whl (44.6 kB view details)

Uploaded Python 2

File details

Details for the file eztemplate-0.3.0.tar.gz.

File metadata

  • Download URL: eztemplate-0.3.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for eztemplate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b5faa08567157184c980a0864d19c0402b0aecd4c37ee7301740a6f14c16fbc6
MD5 ddfa2cf632ad1d9324e14b00503fe8ff
BLAKE2b-256 275f3a6b5c7155dc04dc19165059e053b0b5db7e43636299e4dd228244140182

See more details on using hashes here.

File details

Details for the file eztemplate-0.3.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for eztemplate-0.3.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 f9e1525883f23233fff4143c729b785584e16afb7ee569d106c6117e16d456f3
MD5 2f057ece5387ffeec965e7418234f7bb
BLAKE2b-256 3d50509e8c19b2d9c5f6cdefe760d6b6e97eac888355a96356ca1f31e6786b47

See more details on using hashes here.

File details

Details for the file eztemplate-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for eztemplate-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 666b2f4033dc71d4ed835ed28be316b0f3ca6d9fea8b0ffd506a89efe23f87fb
MD5 e607b2e1049b74e0e1757fd980e826a5
BLAKE2b-256 9c9bdb5e5fa5e8c3ac728b8ac568d381ff9dbd1a27f5612d228929f67a41a51e

See more details on using hashes here.

File details

Details for the file eztemplate-0.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for eztemplate-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 7437f7bd6687dfb77e2e9417867dea722ab896a7968f1095466e5724ffdc293c
MD5 b187e6707c8b6249739ed56da84596ee
BLAKE2b-256 0494f0c92b4ec9945cd5e45910cb98c420640893e3ab109a41ce1791c28fb5a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page