diff --git a/README.md b/README.md index c00d8324a..c5d2c0a46 100644 --- a/README.md +++ b/README.md @@ -2,31 +2,141 @@ # Rougail -Created by: -EOLE (http://eole.orion.education.fr) -Copyright (C) 2005-2018 +## Description -Forked by: -Cadoles (http://www.cadoles.com) -Copyright (C) 2019-2021 +Rougail is a free full-featured configuration manager library written in python3. -Silique (https://www.silique.fr) -Copyright (C) 2022 +The configuration is describe in YAML ou XML dictionary files. -distribued with GPL-2 or later license +Those dictionaries are converted into [Tiramisu](https://framagit.org/tiramisu/tiramisu) objects and can generates configuration files with template written in [Cheetah](https://cheetahtemplate.org/) or [Jinja](https://jinja.palletsprojects.com/). -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. +Rougail can be incorporated with other technologies and stacks regardless of whether they’re written in Python or not. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +## Simple example -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +Create directories: -[Documentation (french)](doc/README.md) +```bash +# mkdir dict tmpl tmp dest +``` + +### Dictionary + +A dictionary is a services and a variables description file. + +Create the file `dict/dictionary.yml`: + +```yml +version: '0.10' + +# describe a first service with a single file +services: +- service: + - name: my_service + file: + - engine: jinja2 + text: /etc/filename + +# describe a variable my_first_variable +# and a family with a variable my_second_variable +variables: +- variable: + name: my_first_variable + value: + - text: my_value +- family: + name: my_family + variables: + - variable: + name: my_second_variable + type: number + mandatory: true + value: + - text: 1 +``` + +### Template + +Create a [Jinja](https://jinja.palletsprojects.com/) template `tmpl/filename`: + +``` +My first value: {{ my_first_variable }} +My second value: {{ my_second_variable }} +``` + +### Generate template + +#### With default value: + +Here is a python3 example file: + +```python +from rougail import Rougail, RougailConfig +from asyncio import run + +async def main(): + RougailConfig['dictionaries_dir'] = ['dict'] + RougailConfig['templates_dir'] = ['tmpl'] + RougailConfig['tmp_dir'] = 'tmp' + RougailConfig['destinations_dir'] = 'dest' + rougail = Rougail() + await rougail.template() + + +run(main()) +``` + +The destination file is generated: + +```bash +# cat dest/etc/filename +My first value: my_value +My second value: 1 +``` + +#### With modified value + +Remove old generated file: + +```bash +# rm -f dest/etc/filename +``` + +Use [Tiramisu](https://framagit.org/tiramisu/tiramisu) API to change values: + +```python +from rougail import Rougail, RougailConfig +from asyncio import run + +async def main(): + RougailConfig['dictionaries_dir'] = ['dict'] + RougailConfig['templates_dir'] = ['tmpl'] + RougailConfig['tmp_dir'] = 'tmp' + RougailConfig['destinations_dir'] = 'dest' + rougail = Rougail() + config = await rougail.get_config() + await config.option('rougail.my_first_variable').value.set('modified_value') + await config.option('rougail.my_family.my_second_variable').value.set(2) + await rougail.template() + + +run(main()) +``` + +The destination file is generated with new values: + +```bash +# cat dest/etc/filename +My first value: modified_value +My second value: 2 +``` + +# Link + +* [Documentation (french)](doc/README.md) +* [Licence ](LICENSE) + +# Related projects + +* [Tiramisu](https://framagit.org/tiramisu/tiramisu) +* [Risotto](https://cloud.silique.fr/gitea/risotto/risotto) diff --git a/doc/variable/README.md b/doc/variable/README.md index 3bab54f21..a2b7d7cb0 100644 --- a/doc/variable/README.md +++ b/doc/variable/README.md @@ -137,7 +137,7 @@ En YAML : - variable: name: my_variable multi: true - unique: false + unique: false ``` ## Variable invisible diff --git a/logo.svg b/logo.svg index df920a83f..14da07da2 100644 --- a/logo.svg +++ b/logo.svg @@ -13,8 +13,8 @@ height="386.79742" inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)" inkscape:export-filename="/home/gnunux/git/risotto/rougail/logo.png" - inkscape:export-xdpi="216.39999" - inkscape:export-ydpi="216.39999" + inkscape:export-xdpi="48" + inkscape:export-ydpi="48" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" @@ -29,8 +29,8 @@ inkscape:pagecheckerboard="0" showgrid="false" inkscape:zoom="1.2346747" - inkscape:cx="89.497256" - inkscape:cy="265.65701" + inkscape:cx="257.15275" + inkscape:cy="152.26683" inkscape:window-width="2048" inkscape:window-height="1083" inkscape:window-x="0"