feat: copy from rougail-output-exporter

This commit is contained in:
egarette@silique.fr 2024-11-28 08:19:41 +01:00
parent b118c303a0
commit 94c6336f5d
7 changed files with 375 additions and 0 deletions

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.1.0"
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,145 @@
"""
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 .i18n import _
class RougailOutputJson:
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
self.rougailconfig = rougailconfig
self.config = config
self.read_write = self.rougailconfig["json.read_write"]
self.is_mandatory = self.rougailconfig["json.mandatory"]
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 exporter(self) -> bool:
self.config.property.read_write()
self.mandatory()
if self.read_write:
self.config.property.read_write()
else:
self.config.property.read_only()
# errors = self.user_data_errors + self.errors
# if errors:
# self.display_errors(errors)
# if self.errors:
# return False
# warnings = self.user_data_warnings + self.warnings
# if warnings:
# self.display_warnings(warnings)
self.parse_family(
self.config,
self.dico,
)
return True
def run(self) -> None:
self.exporter()
print(dumps(self.dico, ensure_ascii=False, indent=2))
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