Skip to main content

Vars collector and template runner.

Project description

c2c.template

Supported template Jinja, Mako, Template.

Tools that collect some vars and get them to a template engine.

Supported template: Jinja, Mako and Template.

Use c2c-template --help to get the command line help.

Vars file

The vars collector gets the vars from YAML files like this one:

extends: inherit.yaml

vars:
     string_var: a string
     int_var: 42
     interpreted_var: __import__('datetime').date.today()
     combined_var: 'Today: {interpreted_var:%Y-%m-%d}'
     facter_json: /usr/bin/facter --json
     facter_yaml: /usr/bin/facter --yaml
     pi: console.log(Math.PI.toPrecision(3))
     obj:
         v1: 1
         v2: '2'
         v3: [1, 2, 3]

 interpreted:
     python:
     - interpreted_var
     bash:
     - facter_json
     - facter_yaml
     json:
     - facter_json
     yaml:
     - facter_yaml
     node:
         vars: ["pi"]
         cmd: ["node", "-e"]

 update_path:
 - obj

The inherit.yaml is an other file with the same syntax that will provide initial vars.

The vars section is where we define the vars values, the YAML files support typing, than 42 will be an integer.

The interpreted configuration to interpret some vars, python, bash, environ, json, yaml are predefined interpreter, node is a custom interpreter.

The update_path is a list of ‘.’-separated paths that will be updated (for dicts) or appended (for lists), instead of overwritten. The sub path will be implicitly added.

We can reuse predefined variables and format them (see combined_var), See: str.format().

Example of usage

Interpret variable in a template

c2c-template --vars vars.yaml --engine jinja --files template.jinja

The result will be stored in a file named template.

Get the vars

It can be useful to get the variable outside.

`c2c-template --vars vars.yaml --get-vars INT_VAR=int_var string_var`

That will set the bash variable INT_VAR to 42, and STRING_VAR to ‘a string’.

Get a configuration file

c2c-template --vars vars.yaml --get-config config.yaml string-var int-var combined-var

Will create a file named config.yaml this:

string-var: a string
int-var: 42
combined-var: Today: 2014-12-12

Build a set of file based on a template

Create the following vars file (vars.yaml):

vars:
    var1: common
    iter:
    - name: one
      var2: first
    - name: two
      var2: second

And the following template (template.jinja):

var1: {{ var1 }}
var2: {{ var2 }}

And run the following command:

c2c-template --vars vars.yaml --files-builder template.jinja {name}.txt iter

This will create two files:

the one.txt file, with:

var1: common
var2: first

The two.txt file, with:

var1: common
var2: second

Project details


Download files

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

Source Distribution

c2c.template-1.3.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distributions

c2c.template-1.3.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

c2c.template-1.3.0-py2-none-any.whl (10.3 kB view details)

Uploaded Python 2

File details

Details for the file c2c.template-1.3.0.tar.gz.

File metadata

File hashes

Hashes for c2c.template-1.3.0.tar.gz
Algorithm Hash digest
SHA256 1902e066cba4b547d23d1f558c1969d1d58971a722284977b7a90e57fe3ea13c
MD5 200ba034c65d4c5c4357a0d778832235
BLAKE2b-256 6be9b0f1f5649573263dc654385b1c1c3bb0993a428383ff77ef811785364631

See more details on using hashes here.

Provenance

File details

Details for the file c2c.template-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for c2c.template-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aec8b61fec99782d8deb8b8ea6dcc10ec2645358cc0d5f5f431d383a31389915
MD5 980c44f45bae534965f8417b25be885e
BLAKE2b-256 d997ae451833d92bb26c32328beb554ad2b06f5c961aaa087a1fa021c23a234b

See more details on using hashes here.

Provenance

File details

Details for the file c2c.template-1.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for c2c.template-1.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 a4f150324927b67bf0e31565aa40ce15a26a825b15fb193d221f11f8832cd0de
MD5 aa7e13607599b3fa1aa4a1634d7f1a1d
BLAKE2b-256 443afcf71131e16408608db35e76f476b6d7d8ba800b242ef61df4d1528e199e

See more details on using hashes here.

Provenance

Supported by

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