c2c.template
============
Supported template Jinja, Mako, Template.
Tools that collect some vars and get them to a template engine.
Supported template: `Jinja <http://jinja.pocoo.org/>`_ and
`Mako <http://www.makotemplates.org/>`_.
Use ``c2c-template --help`` to get the command line help.
Vars file
=========
The vars collector gets the vars from YAML files like this one:
.. code:: yaml
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() <https://docs.python.org/2/library/string.html#formatstrings>`_.
Example of usage
================
Interpret variable in a template
--------------------------------
.. code:: bash
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.
.. code:: bash
`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
------------------------
.. code:: bash
c2c-template --vars vars.yaml --get-config config.yaml string-var int-var combined-var
Will create a file named ``config.yaml`` this:
.. code:: yaml
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``):
.. code:: yaml
vars:
var1: common
iter:
- name: one
var2: first
- name: two
var2: second
And the following template (``template.jinja``):
.. code::
var1: {{ var1 }}
var2: {{ var2 }}
And run the following command:
.. code:: bash
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
Raw data
{
"_id": null,
"home_page": "https://github.com/camptocamp/c2c.template",
"name": "c2c.template",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "template",
"author": "Camptocamp",
"author_email": "info@camptocamp.com",
"download_url": "https://files.pythonhosted.org/packages/88/38/00337d81d556659ac4a3b881281ab4929a5300956518f43ab38586107560/c2c_template-2.4.2.tar.gz",
"platform": null,
"description": "c2c.template\n============\n\nSupported template Jinja, Mako, Template.\n\nTools that collect some vars and get them to a template engine.\n\nSupported template: `Jinja <http://jinja.pocoo.org/>`_ and\n`Mako <http://www.makotemplates.org/>`_.\n\nUse ``c2c-template --help`` to get the command line help.\n\nVars file\n=========\n\nThe vars collector gets the vars from YAML files like this one:\n\n.. code:: yaml\n\n extends: inherit.yaml\n\n vars:\n string_var: a string\n int_var: 42\n interpreted_var: __import__('datetime').date.today()\n combined_var: 'Today: {interpreted_var:%Y-%m-%d}'\n facter_json: /usr/bin/facter --json\n facter_yaml: /usr/bin/facter --yaml\n pi: console.log(Math.PI.toPrecision(3))\n obj:\n v1: 1\n v2: '2'\n v3: [1, 2, 3]\n\n interpreted:\n python:\n - interpreted_var\n bash:\n - facter_json\n - facter_yaml\n json:\n - facter_json\n yaml:\n - facter_yaml\n node:\n vars: [\"pi\"]\n cmd: [\"node\", \"-e\"]\n\n update_path:\n - obj\n\nThe ``inherit.yaml`` is an other file with the same syntax that will provide\ninitial vars.\n\nThe ``vars`` section is where we define the vars values, the YAML files\nsupport typing, than ``42`` will be an integer.\n\nThe ``interpreted`` configuration to interpret some vars,\n``python``, ``bash``, ``environ``, ``json``, ``yaml`` are predefined\ninterpreter, ``node`` is a custom interpreter.\n\nThe ``update_path`` is a list of '.'-separated paths that will be updated (for dicts)\nor appended (for lists), instead of overwritten. The sub path will be implicitly added.\n\nWe can reuse predefined variables and format them (see ``combined_var``),\nSee: `str.format() <https://docs.python.org/2/library/string.html#formatstrings>`_.\n\n\nExample of usage\n================\n\n\nInterpret variable in a template\n--------------------------------\n\n.. code:: bash\n\n c2c-template --vars vars.yaml --engine jinja --files template.jinja\n\nThe result will be stored in a file named ``template``.\n\n\nGet the vars\n------------\n\nIt can be useful to get the variable outside.\n\n.. code:: bash\n\n `c2c-template --vars vars.yaml --get-vars INT_VAR=int_var string_var`\n\nThat will set the bash variable ``INT_VAR`` to 42, and ``STRING_VAR`` to 'a string'.\n\n\nGet a configuration file\n------------------------\n\n.. code:: bash\n\n c2c-template --vars vars.yaml --get-config config.yaml string-var int-var combined-var\n\nWill create a file named ``config.yaml`` this:\n\n.. code:: yaml\n\n string-var: a string\n int-var: 42\n combined-var: Today: 2014-12-12\n\n\nBuild a set of file based on a template\n---------------------------------------\n\nCreate the following vars file (``vars.yaml``):\n\n.. code:: yaml\n\n vars:\n var1: common\n iter:\n - name: one\n var2: first\n - name: two\n var2: second\n\nAnd the following template (``template.jinja``):\n\n.. code::\n\n var1: {{ var1 }}\n var2: {{ var2 }}\n\nAnd run the following command:\n\n.. code:: bash\n\n c2c-template --vars vars.yaml --files-builder template.jinja {name}.txt iter\n\nThis will create two files:\n\nthe ``one.txt`` file, with::\n\n var1: common\n var2: first\n\nThe ``two.txt`` file, with::\n\n var1: common\n var2: second\n\n",
"bugtrack_url": null,
"license": "BSD-2-Clause",
"summary": "Vars collector and template runner.",
"version": "2.4.2",
"project_urls": {
"Homepage": "https://github.com/camptocamp/c2c.template",
"Repository": "https://github.com/camptocamp/c2c.template"
},
"split_keywords": [
"template"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "88bebd606b328f174d13ba5ed29955286dced8a9c6d448c93eee13ea212fcbd8",
"md5": "ed56531cb52da5ef4500228552f49a39",
"sha256": "c074485d0c4020810dc6870545f5602704da95c8c8422f75faa73fc997c741fa"
},
"downloads": -1,
"filename": "c2c_template-2.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ed56531cb52da5ef4500228552f49a39",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 12113,
"upload_time": "2024-04-15T13:37:30",
"upload_time_iso_8601": "2024-04-15T13:37:30.098540Z",
"url": "https://files.pythonhosted.org/packages/88/be/bd606b328f174d13ba5ed29955286dced8a9c6d448c93eee13ea212fcbd8/c2c_template-2.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "883800337d81d556659ac4a3b881281ab4929a5300956518f43ab38586107560",
"md5": "70a42f3c2319aa942db43a47de25138c",
"sha256": "5582ee975eed7573f558b9318874033098864efff3911f98efd2fd8c41f59602"
},
"downloads": -1,
"filename": "c2c_template-2.4.2.tar.gz",
"has_sig": false,
"md5_digest": "70a42f3c2319aa942db43a47de25138c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 11275,
"upload_time": "2024-04-15T13:37:31",
"upload_time_iso_8601": "2024-04-15T13:37:31.937092Z",
"url": "https://files.pythonhosted.org/packages/88/38/00337d81d556659ac4a3b881281ab4929a5300956518f43ab38586107560/c2c_template-2.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-15 13:37:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "camptocamp",
"github_project": "c2c.template",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "poetry",
"specs": [
[
"==",
"1.8.2"
]
]
},
{
"name": "poetry-plugin-tweak-dependencies-version",
"specs": [
[
"==",
"1.5.2"
]
]
},
{
"name": "pip",
"specs": [
[
"==",
"24.0"
]
]
},
{
"name": "poetry-dynamic-versioning",
"specs": [
[
"==",
"1.2.0"
]
]
},
{
"name": "poetry-plugin-export",
"specs": [
[
"==",
"1.7.1"
]
]
},
{
"name": "poetry-plugin-drop-python-upper-constraint",
"specs": [
[
"==",
"0.1.0"
]
]
}
],
"lcname": "c2c.template"
}