rougail/README.md

105 lines
2.3 KiB
Markdown
Raw Normal View History

2022-11-06 10:27:05 +01:00
![Logo Rougail](logo.png "logo rougail")
# Rougail
2021-02-10 08:21:06 +01:00
2022-11-06 16:40:29 +01:00
## Description
2021-02-10 08:21:06 +01:00
2022-11-06 16:40:29 +01:00
Rougail is a free full-featured configuration manager library written in python3.
2021-02-10 08:21:06 +01:00
2023-10-12 08:17:30 +02:00
The configuration is describe in YAML dictionary files.
2022-11-02 23:00:42 +01:00
2023-10-12 08:17:30 +02:00
Those dictionaries are converted into [Tiramisu](https://framagit.org/tiramisu/tiramisu) objects.
2021-02-10 08:21:06 +01:00
2022-11-06 16:40:29 +01:00
Rougail can be incorporated with other technologies and stacks regardless of whether theyre written in Python or not.
2021-02-10 08:21:06 +01:00
2022-11-06 16:40:29 +01:00
## Simple example
2021-02-10 08:21:06 +01:00
2023-10-12 08:17:30 +02:00
Create a directory:
2021-02-10 08:21:06 +01:00
2022-11-06 16:40:29 +01:00
```bash
2023-10-12 08:17:30 +02:00
# mkdir dict
2022-11-06 16:40:29 +01:00
```
2023-10-12 08:17:30 +02:00
## Dictionary
2022-11-06 16:40:29 +01:00
2023-10-12 08:17:30 +02:00
A dictionary is a variables description file.
2022-11-06 16:40:29 +01:00
Create the file `dict/dictionary.yml`:
```yml
2023-10-12 08:17:30 +02:00
---
version: '1.0'
2022-11-06 16:40:29 +01:00
# describe a variable my_first_variable
# and a family with a variable my_second_variable
2023-10-12 08:17:30 +02:00
my_first_variable:
default: my_value
my_family:
my_second_variable:
type: number
mandatory: true
value: 1
2022-11-06 16:40:29 +01:00
```
2023-10-12 08:17:30 +02:00
## Generate variable
2022-11-06 16:40:29 +01:00
2023-10-12 08:17:30 +02:00
### With default value:
2022-11-06 16:40:29 +01:00
Here is a python3 example file:
```python
from rougail import Rougail, RougailConfig
2023-10-12 08:17:30 +02:00
from pprint import pprint
RougailConfig['dictionaries_dir'] = ['dict']
RougailConfig['templates_dir'] = ['tmpl']
RougailConfig['tmp_dir'] = 'tmp'
RougailConfig['destinations_dir'] = 'dest'
rougail = Rougail()
config = rougail.get_config()
pprint(config.value.get(), sort_dicts=False)
2022-11-06 16:40:29 +01:00
```
2023-10-12 08:17:30 +02:00
The result is:
2022-11-06 16:40:29 +01:00
2023-10-12 08:17:30 +02:00
```json
{'rougail.my_first_variable': 'my_value',
'rougail.my_family.my_second_variable': 1}
2022-11-06 16:40:29 +01:00
```
2023-10-12 08:17:30 +02:00
### With modified value
2022-11-06 16:40:29 +01:00
Use [Tiramisu](https://framagit.org/tiramisu/tiramisu) API to change values:
```python
from rougail import Rougail, RougailConfig
2023-10-12 08:17:30 +02:00
from pprint import pprint
RougailConfig['dictionaries_dir'] = ['dict']
RougailConfig['templates_dir'] = ['tmpl']
RougailConfig['tmp_dir'] = 'tmp'
RougailConfig['destinations_dir'] = 'dest'
rougail = Rougail()
config = rougail.get_config()
config.option('rougail.my_first_variable').value.set('modified_value')
config.option('rougail.my_family.my_second_variable').value.set(2)
pprint(config.value.get(), sort_dicts=False)
2022-11-06 16:40:29 +01:00
```
The destination file is generated with new values:
2023-10-12 08:17:30 +02:00
```json
{'rougail.my_first_variable': 'modified_value',
'rougail.my_family.my_second_variable': 2}
2022-11-06 16:40:29 +01:00
```
# Link
2023-10-12 08:17:30 +02:00
* [Documentation](doc/README.md)
2022-11-06 16:40:29 +01:00
* [Licence ](LICENSE)
# Related projects
2023-10-12 08:17:30 +02:00
* [Tiramisu](https://forge.cloud.silique.fr/gnunux/tiramisu)
2022-11-06 16:40:29 +01:00
* [Risotto](https://cloud.silique.fr/gitea/risotto/risotto)