Compare commits

...

7 commits

1854 changed files with 17753 additions and 10 deletions

View file

@ -1,16 +1,23 @@
## 0.1.0rc1 (2024-11-06)
### Fix
- update rougail dependency
## 0.1.0rc0 (2024-11-01)
## 0.2.0a0 (2024-12-11)
### Feat
- support auto_save variable
- add error and warnings informations in json
- add tests
### Fix
- black
- license, pyproject and so on
- update tests
## 0.1.1a0 (2024-11-28)
### Fix
- separation between run and print function
## 0.1.0 (2024-11-28)
### Feat
- copy from rougail-output-exporter
- init commit

View file

@ -0,0 +1,57 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2024-11-01 11:03+0100\n"
"PO-Revision-Date: 2024-11-01 11:04+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 3.5\n"
#: src/rougail/output_exporter/__init__.py:73
msgid "The following variables are mandatory but have no value:"
msgstr "Les variables suiveuses sont obligatoire mais n'ont pas de valeur :"
#: src/rougail/output_exporter/__init__.py:84
msgid "The following variables are inaccessible but are empty and mandatory :"
msgstr "Les variables suiveuses sont inaccessibles mais sont vides et obligatoires :"
#: src/rougail/output_exporter/output/console.py:53
msgid "Undocumented variable"
msgstr "Variable non documentée"
#: src/rougail/output_exporter/output/console.py:54
msgid "Undocumented but modified variable"
msgstr "Variable non documentée mais modifiée"
#: src/rougail/output_exporter/output/console.py:57
msgid "Unmodifiable variable"
msgstr "Variable non modifiable"
#: src/rougail/output_exporter/output/console.py:61
msgid "Default value"
msgstr "Valeur par défaut"
#: src/rougail/output_exporter/output/console.py:62
msgid "Modified value"
msgstr "Valeur modifiée"
#: src/rougail/output_exporter/output/console.py:63
msgid "Original default value"
msgstr "Valeur par défaut d'origine"
#: src/rougail/output_exporter/output/console.py:67
msgid "Caption"
msgstr "Légende"
#: src/rougail/output_exporter/output/console.py:92
msgid "Variables:"
msgstr "Variables :"

View file

@ -0,0 +1,57 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-11-01 11:03+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
#: src/rougail/output_exporter/__init__.py:73
msgid "The following variables are mandatory but have no value:"
msgstr ""
#: src/rougail/output_exporter/__init__.py:84
msgid "The following variables are inaccessible but are empty and mandatory :"
msgstr ""
#: src/rougail/output_exporter/output/console.py:53
msgid "Undocumented variable"
msgstr ""
#: src/rougail/output_exporter/output/console.py:54
msgid "Undocumented but modified variable"
msgstr ""
#: src/rougail/output_exporter/output/console.py:57
msgid "Unmodifiable variable"
msgstr ""
#: src/rougail/output_exporter/output/console.py:61
msgid "Default value"
msgstr ""
#: src/rougail/output_exporter/output/console.py:62
msgid "Modified value"
msgstr ""
#: src/rougail/output_exporter/output/console.py:63
msgid "Original default value"
msgstr ""
#: src/rougail/output_exporter/output/console.py:67
msgid "Caption"
msgstr ""
#: src/rougail/output_exporter/output/console.py:92
msgid "Variables:"
msgstr ""

40
pyproject.toml Normal file
View file

@ -0,0 +1,40 @@
[build-system]
build-backend = "flit_core.buildapi"
requires = ["flit_core >=3.8.0,<4"]
[project]
name = "rougail.output_json"
version = "0.2.0a0"
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
readme = "README.md"
description = "Rougail output json"
requires-python = ">=3.8"
license = {file = "LICENSE"}
classifiers = [
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
"Natural Language :: English",
"Natural Language :: French",
]
dependencies = [
"rougail >= 1.1,<2",
]
[project.urls]
Home = "https://forge.cloud.silique.fr/stove/rougail-output-json"
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$version"
version_scheme = "pep440"
version_provider = "pep621"
update_changelog_on_bump = true
changelog_merge_prerelease = true

View file

@ -0,0 +1,165 @@
"""
Silique (https://www.silique.fr)
Copyright (C) 2022-2024
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from typing import Any, List, Optional
from json import dumps
from tiramisu import undefined
from tiramisu.error import PropertiesOptionError, ConfigError
from rougail.error import ExtentionError
from .i18n import _
class RougailOutputJson:
output_name = 'json'
def __init__(
self,
config: "Config",
*,
rougailconfig: "RougailConfig" = None,
user_data_errors: Optional[list] = None,
user_data_warnings: Optional[list] = None,
) -> None:
if rougailconfig is None:
from rougail import RougailConfig
rougailconfig = RougailConfig
rougailconfig["step.output"] = self.output_name
if rougailconfig["step.output"] != self.output_name:
raise ExtentionError(_('the "step.output" is not set to "{0}"').format(self.output_name))
self.rougailconfig = rougailconfig
self.config = config
if user_data_errors:
self.errors = user_data_errors
else:
self.errors = []
if user_data_warnings:
self.warnings = user_data_warnings
else:
self.warnings = []
self.read_write = self.rougailconfig["json.read_write"]
self.is_mandatory = self.rougailconfig["json.mandatory"]
self.dico = {}
def run(self) -> None:
self.exporter()
return dumps(self.dico, ensure_ascii=False, indent=2) + '\n'
def print(self) -> str:
print(self.run())
def exporter(self) -> None:
self.config.property.read_write()
self.mandatory()
self.manage_warnings()
self.config.property.read_only()
if self.manage_errors():
return
if self.read_write:
self.config.property.read_write()
self.parse_family(
self.config,
self.dico,
)
def mandatory(self):
if not self.is_mandatory:
return
title = False
options_with_error = []
try:
mandatories = self.config.value.mandatory()
except (ConfigError, PropertiesOptionError) as err:
self.errors.append(f"Error in config: {err}")
return
for option in mandatories:
try:
option.value.get()
if not title:
# self.errors.append("Les variables suivantes sont obligatoires mais n'ont pas de valeur :")
self.errors.append(
_("The following variables are mandatory but have no value:")
)
title = True
self.errors.append(f" - {option.description()}")
except PropertiesOptionError:
options_with_error.append(option)
if not title:
for idx, option in enumerate(options_with_error):
if not idx:
# self.errors.append("Les variables suivantes sont inaccessibles mais sont vides et obligatoires :")
self.errors.append(
_(
"The following variables are inaccessible but are empty and mandatory :"
)
)
self.errors.append(f" - {option.description()}")
def manage_warnings(self) -> None:
if self.warnings:
self.dico["_warnings"] = self.warnings
def manage_errors(self) -> bool:
if not self.errors:
return False
self.dico = {"_errors": self.errors}
return True
def parse_family(
self,
conf,
child,
):
for option in conf:
if option.isoptiondescription():
if option.isleadership():
parent = []
self.parse_leadership(
option,
parent,
)
else:
parent = {}
self.parse_family(option, parent)
child[option.name()] = parent
else:
child[option.name()] = option.value.get()
def parse_leadership(
self,
conf,
parent,
):
leader, *followers = list(conf)
leader_values = leader.value.get()
for idx, leader_value in enumerate(leader_values):
leader_dict = {leader.name(): leader_value}
parent.append(leader_dict)
for follower in list(followers):
if follower.index() != idx:
continue
followers.remove(follower)
leader_dict[follower.name()] = follower.value.get()
RougailOutput = RougailOutputJson
__all__ = ("RougailOutputJson",)

View file

@ -0,0 +1,52 @@
"""
Silique (https://www.silique.fr)
Copyright (C) 2024
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from pathlib import Path
def get_rougail_config(
*,
backward_compatibility=True,
) -> dict:
options = """
json:
description: Configuration rougail-json
disabled:
type: jinja
jinja: |
{% if step.output != 'json' %}
disabled
{% endif %}
read_write:
description: Display variables available in read_write mode
negative_description: Display variables available in read_only mode
default: false
mandatory:
description: Test mandatories variable before display in json
negative_description: Do not test mandatories variable before display in json
default: true
"""
return {
"name": "json",
"process": "output",
"options": options,
"level": 50,
}
__all__ = ("get_rougail_config",)

View file

@ -0,0 +1,24 @@
"""Internationalisation utilities
Silique (https://www.silique.fr)
Copyright (C) 2024
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
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 Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from gettext import translation
from pathlib import Path
t = translation("rougail_output_json", str(Path(__file__).parent / "locale"), fallback=True)
_ = t.gettext

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,3 @@
{
"version": "string1"
}

View file

@ -0,0 +1,3 @@
{
"empty": "string1"
}

View file

@ -0,0 +1,8 @@
{
"var1": "string1",
"var2": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,12 @@
{
"var1": [
"string1",
"string2",
"string3"
],
"var2": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,10 @@
{
"var1": [
"domain1.lan",
"domain2.lan"
],
"var2": [
"domain1.lan",
"domain2.lan"
]
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"without_type": "string1"
}

View file

@ -0,0 +1,8 @@
{
"var1": true,
"var2": true,
"var3": true,
"var4": true,
"var5": true,
"var6": true
}

View file

@ -0,0 +1,3 @@
{
"variable": true
}

View file

@ -0,0 +1,8 @@
{
"var1": "a",
"var2": "a",
"var3": "a",
"var4": null,
"var5": "a",
"var6": 1
}

View file

@ -0,0 +1,3 @@
{
"var": 0
}

View file

@ -0,0 +1,8 @@
{
"var1": [
"string1",
"string2",
"string3"
],
"var2": "string1"
}

View file

@ -0,0 +1,4 @@
{
"custom1": "string1",
"custom2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "domain1.lan"
}

View file

@ -0,0 +1,3 @@
{
"variable": "domain1.lan"
}

View file

@ -0,0 +1,8 @@
{
"var1": 1.1,
"var2": 1.1,
"var3": 1.1,
"var4": 1.1,
"var5": 1.1,
"var6": 1.1
}

View file

@ -0,0 +1,8 @@
{
"var1": 1,
"var2": 1,
"var3": 1,
"var4": 1,
"var5": 1,
"var6": 1
}

View file

@ -0,0 +1,5 @@
{
"variable1": "80",
"variable2": "80",
"variable3": "80"
}

View file

@ -0,0 +1,3 @@
{
"var": "#b1b1b1"
}

View file

@ -0,0 +1,8 @@
{
"var1": "string1",
"var2": "string1",
"var3": "string1",
"var4": "string1",
"var5": "string1",
"var6": "string1"
}

View file

@ -0,0 +1,3 @@
{
"var": "quote'"
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,11 @@
{
"var1": "test",
"var2": "test",
"var3": "test1",
"var4": null,
"var5": false,
"var6": [
"test1",
"test2"
]
}

View file

@ -0,0 +1,10 @@
{
"variable1": [
"val1",
"val2"
],
"variable2": [
"val1",
"val2"
]
}

View file

@ -0,0 +1,5 @@
{
"source_variable_1": "string1",
"source_variable_2": "string1",
"my_variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"var": "string1"
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}

View file

@ -0,0 +1,8 @@
{
"my_variable": "string1",
"my_calculated_variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,8 @@
{
"my_variable": "string1",
"my_calculated_variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,7 @@
{
"my_calculated_variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,12 @@
{
"my_variable": [
"string1",
"string2",
"string3"
],
"my_calculated_variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"var": 0
}

View file

@ -0,0 +1,26 @@
{
"var1": [
true
],
"var2": [
true
],
"var3": [
true
],
"var4": [
true
],
"var5": [
true
],
"var6": [
true
],
"var7": [
true
],
"var8": [
true
]
}

View file

@ -0,0 +1,12 @@
{
"custom1": [
"string1",
"string2",
"string3"
],
"custom2": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,42 @@
{
"var1": [
1.1,
2.2,
3.3
],
"var2": [
1.1,
2.2,
3.3
],
"var3": [
1.1,
2.2,
3.3
],
"var4": [
1.1,
2.2,
3.3
],
"var5": [
1.1,
2.2,
3.3
],
"var6": [
1.1,
2.2,
3.3
],
"var7": [
1.1,
2.2,
3.3
],
"var8": [
1.1,
2.2,
3.3
]
}

View file

@ -0,0 +1,42 @@
{
"var1": [
1,
2,
3
],
"var2": [
1,
2,
3
],
"var3": [
1,
2,
3
],
"var4": [
1,
2,
3
],
"var5": [
1,
2,
3
],
"var6": [
1,
2,
3
],
"var7": [
1,
2,
3
],
"var8": [
1,
2,
3
]
}

View file

@ -0,0 +1,7 @@
{
"var1": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,38 @@
{
"var1": [
"string1",
"string2",
"string3"
],
"var2": [
"string1",
"string2",
"string3"
],
"var3": "string1",
"var4": [
"string1",
"string2",
"string3"
],
"var5": [
"string1",
"string2",
"string3"
],
"var6": [
"string1",
"string2",
"string3"
],
"var7": [
"string1",
"string2",
"string3"
],
"var8": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,7 @@
{
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,7 @@
{
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,7 @@
{
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,7 @@
{
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,8 @@
{
"variable1": [
"string1",
"string2",
"string3"
],
"variable2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"int": 1
}

View file

@ -0,0 +1,3 @@
{
"variable": "no"
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "no"
}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "yes"
}

View file

@ -0,0 +1,3 @@
{
"var": "yes"
}

View file

@ -0,0 +1,5 @@
{
"var1": "string1",
"var2": "string1",
"var3": "string1"
}

View file

@ -0,0 +1,5 @@
{
"var1": "string1",
"var2": "string1",
"var3": "string1"
}

View file

@ -0,0 +1,5 @@
{
"condition": "string1",
"var1": null,
"var2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"condition": true
}

View file

@ -0,0 +1,3 @@
{
"condition": true
}

View file

@ -0,0 +1,4 @@
{
"condition": "string1",
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"condition": "string1"
}

View file

@ -0,0 +1,3 @@
{
"int": 1
}

View file

@ -0,0 +1,4 @@
{
"var1": "another_value",
"var2": "string1"
}

View file

@ -0,0 +1,7 @@
{
"var1": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,6 @@
{
"var1": [
"val1",
"val2"
]
}

View file

@ -0,0 +1,7 @@
{
"var1": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,7 @@
{
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,3 @@
{
"var": "no"
}

View file

@ -0,0 +1,3 @@
{
"var": "string1"
}

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,4 @@
{
"var1": "string1",
"var2": "string1"
}

View file

@ -0,0 +1,3 @@
{
"var1": "yes"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "a"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,3 @@
{
"variable": "string1"
}

View file

@ -0,0 +1,5 @@
{
"family": {
"variable": "string1"
}
}

View file

@ -0,0 +1,5 @@
{
"family": {
"variable": "string1"
}
}

View file

@ -0,0 +1,3 @@
{
"variable": "no"
}

View file

@ -0,0 +1,7 @@
{
"variable": [
"string1",
"string2",
"string3"
]
}

View file

@ -0,0 +1,4 @@
{
"condition": "string1",
"variable": "string1"
}

View file

@ -0,0 +1,5 @@
{
"var1": "test1",
"var2": "test1",
"var3": "string1"
}

View file

@ -0,0 +1,3 @@
{
"var": "a"
}

View file

@ -0,0 +1,8 @@
{
"family1": {
"variable1": "string1"
},
"family2": {
"variable2": "string1"
}
}

View file

@ -0,0 +1,3 @@
{
"var": "string1"
}

View file

@ -0,0 +1,3 @@
{
"leader": []
}

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,6 @@
{
"family": {
"var1": "string1",
"var2": "string1"
}
}

Some files were not shown because too many files have changed in this diff Show more