Compare commits
No commits in common. "0.1.0a3" and "main" have entirely different histories.
12 changed files with 1 additions and 612 deletions
31
CHANGELOG.md
31
CHANGELOG.md
|
|
@ -1,31 +0,0 @@
|
||||||
## 0.1.0a3 (2025-12-30)
|
|
||||||
|
|
||||||
### Fix
|
|
||||||
|
|
||||||
- update doc
|
|
||||||
|
|
||||||
## 0.1.0a2 (2025-12-22)
|
|
||||||
|
|
||||||
### Feat
|
|
||||||
|
|
||||||
- add frozen variable support
|
|
||||||
|
|
||||||
### Fix
|
|
||||||
|
|
||||||
- do not force description format
|
|
||||||
- update doc
|
|
||||||
- refactoring
|
|
||||||
- update translation
|
|
||||||
|
|
||||||
## 0.1.0a1 (2025-11-21)
|
|
||||||
|
|
||||||
### Fix
|
|
||||||
|
|
||||||
- ExtentionError => ExtensionError
|
|
||||||
|
|
||||||
## 0.1.0a0 (2025-11-06)
|
|
||||||
|
|
||||||
### Feat
|
|
||||||
|
|
||||||
- update for last rougail version
|
|
||||||
- support of password type
|
|
||||||
21
README.fr.md
21
README.fr.md
|
|
@ -1,21 +0,0 @@
|
||||||
---
|
|
||||||
gitea: none
|
|
||||||
include_toc: true
|
|
||||||
---
|
|
||||||
[🇬🇧 (EN)](README.md) - [🇫🇷 (FR)](README.fr.md)
|
|
||||||
|
|
||||||
## Définir des données utilisateur interactivement dans la console
|
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
>
|
|
||||||
> L'utilisateur va entrer les valeurs des variables dans une interface en ligne de commande. Ces variables vont être affichées les unes après les autres, permettant à l'utilisateur de changer ou ajouter des valeurs.\
|
|
||||||
> **Chemin** : questionary\
|
|
||||||
> *`désactivé`*\
|
|
||||||
> **Désactivé** : si questionary n'est pas mis dans "[Sélection pour données utilisateur](#step.user_data)"
|
|
||||||
|
|
||||||
| Variable | Description | Valeur par défaut | Type |
|
|
||||||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|---------------------|---------------------------------------------------------------------------------------------------|
|
|
||||||
| **<a id="questionary.mandatory" name="questionary.mandatory">questionary.mandatory</a>**<br/>**Ligne de commande** : <br/>• -qm, --questionary.mandatory<br/>• -nqm, --questionary.no-mandatory<br/>**Variable d'environnement** : QUESTIONARY.MANDATORY | Demander des valeurs uniquement pour des variables obligatoires sans valeur. | false | [`boolean`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `obligatoire` |
|
|
||||||
| **<a id="questionary.show_secrets" name="questionary.show_secrets">questionary.show_secrets</a>**<br/>**Ligne de commande** : <br/>• -qs, --questionary.show_secrets<br/>• -nqs, --questionary.no-show_secrets<br/>**Variable d'environnement** : QUESTIONARY.SHOW_SECRETS | Afficher les secrets plutôt que de les obscurcir. | false | [`boolean`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `obligatoire` |
|
|
||||||
|
|
||||||
|
|
||||||
21
README.md
21
README.md
|
|
@ -1,21 +1,2 @@
|
||||||
---
|
# rougail-user-data-questionary
|
||||||
gitea: none
|
|
||||||
include_toc: true
|
|
||||||
---
|
|
||||||
[🇬🇧 (EN)](README.md) - [🇫🇷 (FR)](README.fr.md)
|
|
||||||
|
|
||||||
## Define user data interactively in the console
|
|
||||||
|
|
||||||
> [!NOTE]
|
|
||||||
>
|
|
||||||
> The user will enter variable values in a command-line interface. The variables will be displayed one after another, allowing the user to change or add values.\
|
|
||||||
> **Path**: questionary\
|
|
||||||
> *`disabled`*\
|
|
||||||
> **Disabled**: if questionary is not set in "[Select for user datas](#step.user_data)"
|
|
||||||
|
|
||||||
| Variable | Description | Default value | Type |
|
|
||||||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|-----------------|-------------------------------------------------------------------------------------------------|
|
|
||||||
| **<a id="questionary.mandatory" name="questionary.mandatory">questionary.mandatory</a>**<br/>**Command line**: <br/>• -qm, --questionary.mandatory<br/>• -nqm, --questionary.no-mandatory<br/>**Environment variable**: QUESTIONARY.MANDATORY | Ask values only for mandatories variables without any value. | false | [`boolean`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `mandatory` |
|
|
||||||
| **<a id="questionary.show_secrets" name="questionary.show_secrets">questionary.show_secrets</a>**<br/>**Command line**: <br/>• -qs, --questionary.show_secrets<br/>• -nqs, --questionary.no-show_secrets<br/>**Environment variable**: QUESTIONARY.SHOW_SECRETS | Show secrets instead of obscuring them. | false | [`boolean`](https://rougail.readthedocs.io/en/latest/variable.html#variables-types) `mandatory` |
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
# SOME DESCRIPTIVE TITLE.
|
|
||||||
# Copyright (C) YEAR ORGANIZATION
|
|
||||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
||||||
#
|
|
||||||
msgid ""
|
|
||||||
msgstr ""
|
|
||||||
"Project-Id-Version: \n"
|
|
||||||
"POT-Creation-Date: 2025-12-29 12:20+0100\n"
|
|
||||||
"PO-Revision-Date: 2025-12-29 12:20+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.8\n"
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:32
|
|
||||||
msgid "Define user data interactively in the console"
|
|
||||||
msgstr "Définir des données utilisateur interactivement dans la console"
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:33
|
|
||||||
msgid ""
|
|
||||||
"The user will enter variable values in a command-line interface. The "
|
|
||||||
"variables will be displayed one after another, allowing the user to change "
|
|
||||||
"or add values."
|
|
||||||
msgstr ""
|
|
||||||
"L'utilisateur va entrer les valeurs des variables dans une interface en "
|
|
||||||
"ligne de commande. Ces variables vont être affichées les unes après les "
|
|
||||||
"autres, permettant à l'utilisateur de changer ou ajouter des valeurs."
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:38
|
|
||||||
msgid "if questionary is not set in \"step.user_data\""
|
|
||||||
msgstr "si questionary n'est pas mis dans \"step.user_data\""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:41
|
|
||||||
msgid "Ask values only for mandatories variables without any value"
|
|
||||||
msgstr ""
|
|
||||||
"Demander des valeurs uniquement pour des variables obligatoires sans valeur"
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:46
|
|
||||||
msgid "Show secrets instead of obscuring them"
|
|
||||||
msgstr "Afficher les secrets plutôt que de les obscurcir"
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/data.py:61
|
|
||||||
msgid "questionary is not set in step.user_data"
|
|
||||||
msgstr "questionary n'est pas mis dans step.user_data"
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/data.py:224
|
|
||||||
msgid "Not a valid {0}"
|
|
||||||
msgstr "N'est pas un valide {0}"
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/data.py:245
|
|
||||||
msgid "Value must not be empty"
|
|
||||||
msgstr "La valeur ne doit pas être vide"
|
|
||||||
|
|
||||||
#~ msgid "when questionary is not set in \"step.user_data\""
|
|
||||||
#~ msgstr "lorsque questionary n'est pas mis dans step.user_data"
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
# SOME DESCRIPTIVE TITLE.
|
|
||||||
# Copyright (C) YEAR ORGANIZATION
|
|
||||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
|
||||||
#
|
|
||||||
msgid ""
|
|
||||||
msgstr ""
|
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
|
||||||
"POT-Creation-Date: 2025-12-29 12:20+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/user_data_questionary/config.py:32
|
|
||||||
msgid "Define user data interactively in the console"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:33
|
|
||||||
msgid "The user will enter variable values in a command-line interface. The variables will be displayed one after another, allowing the user to change or add values."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:38
|
|
||||||
msgid "if questionary is not set in \"step.user_data\""
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:41
|
|
||||||
msgid "Ask values only for mandatories variables without any value"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/config.py:46
|
|
||||||
msgid "Show secrets instead of obscuring them"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/data.py:61
|
|
||||||
msgid "questionary is not set in step.user_data"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/data.py:224
|
|
||||||
msgid "Not a valid {0}"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: src/rougail/user_data_questionary/data.py:245
|
|
||||||
msgid "Value must not be empty"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
[build-system]
|
|
||||||
build-backend = "flit_core.buildapi"
|
|
||||||
requires = ["flit_core >=3.8.0,<4"]
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "rougail.user_data_questionary"
|
|
||||||
version = "0.1.0a3"
|
|
||||||
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
|
||||||
readme = "README.md"
|
|
||||||
description = "Rougail user_data questionary"
|
|
||||||
requires-python = ">=3.11"
|
|
||||||
license = {file = "LICENSE"}
|
|
||||||
classifiers = [
|
|
||||||
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Python :: 3.11",
|
|
||||||
"Programming Language :: Python :: 3.12",
|
|
||||||
"Programming Language :: Python :: 3.13",
|
|
||||||
"Programming Language :: Python :: 3.14",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Operating System :: OS Independent",
|
|
||||||
"Natural Language :: English",
|
|
||||||
"Natural Language :: French",
|
|
||||||
|
|
||||||
]
|
|
||||||
dependencies = [
|
|
||||||
"rougail-base >= 1.1,<2",
|
|
||||||
"questionary ~= 2.1.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[project.urls]
|
|
||||||
Home = "https://forge.cloud.silique.fr/stove/rougail-user-data-questionary"
|
|
||||||
|
|
||||||
[tool.commitizen]
|
|
||||||
name = "cz_conventional_commits"
|
|
||||||
tag_format = "$version"
|
|
||||||
version_scheme = "pep440"
|
|
||||||
version_provider = "pep621"
|
|
||||||
version_files = [
|
|
||||||
"src/rougail/user_data_questionary/__version__.py",
|
|
||||||
"pyproject.toml:version"
|
|
||||||
]
|
|
||||||
update_changelog_on_bump = true
|
|
||||||
changelog_merge_prerelease = true
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
"""
|
|
||||||
Silique (https://www.silique.fr)
|
|
||||||
Copyright (C) 2024-2025
|
|
||||||
|
|
||||||
distribued with GPL-2 or later license
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
"""
|
|
||||||
|
|
||||||
from .data import RougailUserDataQuestionary
|
|
||||||
from .__version__ import __version__
|
|
||||||
|
|
||||||
RougailUserData = RougailUserDataQuestionary
|
|
||||||
__all__ = ("RougailUserDataQuestionary",)
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
"""
|
|
||||||
Silique (https://www.silique.fr)
|
|
||||||
Copyright (C) 2024-2025
|
|
||||||
|
|
||||||
distribued with GPL-2 or later license
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
"""
|
|
||||||
|
|
||||||
__version__ = "0.1.0a3"
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
"""
|
|
||||||
Silique (https://www.silique.fr)
|
|
||||||
Copyright (C) 2024-2025
|
|
||||||
|
|
||||||
distribued with GPL-2 or later license
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
"""
|
|
||||||
|
|
||||||
from .i18n import _
|
|
||||||
|
|
||||||
|
|
||||||
def get_rougail_config(
|
|
||||||
*,
|
|
||||||
backward_compatibility=True,
|
|
||||||
) -> dict:
|
|
||||||
"""generate rougail config"""
|
|
||||||
options = f"""
|
|
||||||
questionary:
|
|
||||||
description: {_("Define user data interactively in the console")}
|
|
||||||
help: {_("The user will enter variable values in a command-line interface. The variables will be displayed one after another, allowing the user to change or add values.")}
|
|
||||||
disabled:
|
|
||||||
jinja: >-
|
|
||||||
{{{{ step.user_data is propertyerror or 'questionary' not in step.user_data }}}}
|
|
||||||
return_type: boolean
|
|
||||||
description: {_('if questionary is not set in "step.user_data"')}
|
|
||||||
|
|
||||||
mandatory:
|
|
||||||
description: {_("Ask values only for mandatories variables without any value")}
|
|
||||||
alternative_name: qm
|
|
||||||
default: false
|
|
||||||
|
|
||||||
show_secrets:
|
|
||||||
description: {_("Show secrets instead of obscuring them")}
|
|
||||||
alternative_name: qs
|
|
||||||
type: boolean
|
|
||||||
default: false
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
"name": "questionary",
|
|
||||||
"process": "user data",
|
|
||||||
"options": options,
|
|
||||||
"level": 60,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ("get_rougail_config",)
|
|
||||||
|
|
@ -1,253 +0,0 @@
|
||||||
"""
|
|
||||||
Silique (https://www.silique.fr)
|
|
||||||
Copyright (C) 2024-2025
|
|
||||||
|
|
||||||
distribued with GPL-2 or later license
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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
|
|
||||||
"""
|
|
||||||
|
|
||||||
import warnings
|
|
||||||
from questionary import (
|
|
||||||
text,
|
|
||||||
select,
|
|
||||||
confirm,
|
|
||||||
password,
|
|
||||||
Validator,
|
|
||||||
ValidationError,
|
|
||||||
print as qprint,
|
|
||||||
)
|
|
||||||
from tiramisu.error import ValueOptionError, ValueErrorWarning, ValueWarning
|
|
||||||
from rougail.tiramisu import CONVERT_OPTION
|
|
||||||
from rougail.config import RougailConfig
|
|
||||||
from rougail.error import ExtensionError
|
|
||||||
|
|
||||||
from .i18n import _
|
|
||||||
|
|
||||||
|
|
||||||
class RougailUserDataQuestionary:
|
|
||||||
"""Rougail userdata for Questionary"""
|
|
||||||
|
|
||||||
interactive_user_data = True
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
config: "Config",
|
|
||||||
*,
|
|
||||||
rougailconfig: "RougailConfig" = None,
|
|
||||||
):
|
|
||||||
# this is the tiramisu config object
|
|
||||||
self.config = config
|
|
||||||
if rougailconfig is None:
|
|
||||||
rougailconfig = RougailConfig
|
|
||||||
user_data = rougailconfig["step.user_data"]
|
|
||||||
if "questionary" not in user_data:
|
|
||||||
user_data.append("questionary")
|
|
||||||
rougailconfig["step.user_data"] = user_data
|
|
||||||
user_data = rougailconfig["step.user_data"]
|
|
||||||
if "questionary" not in user_data:
|
|
||||||
raise ExtensionError(_("questionary is not set in step.user_data"))
|
|
||||||
self.rougailconfig = rougailconfig
|
|
||||||
warnings.simplefilter("always", ValueErrorWarning)
|
|
||||||
warnings.simplefilter("always", ValueWarning)
|
|
||||||
|
|
||||||
def run(
|
|
||||||
self,
|
|
||||||
) -> None:
|
|
||||||
self.errors = []
|
|
||||||
self.warnings = []
|
|
||||||
self.questionary_show_secrets = self.rougailconfig["questionary.show_secrets"]
|
|
||||||
if "demoting_error_warning" not in self.config.property.get():
|
|
||||||
add_demoting = True
|
|
||||||
self.config.property.add("demoting_error_warning")
|
|
||||||
else:
|
|
||||||
add_demoting = False
|
|
||||||
if self.rougailconfig["questionary.mandatory"]:
|
|
||||||
self.parse_mandatories()
|
|
||||||
else:
|
|
||||||
self.parse(self.config)
|
|
||||||
if add_demoting:
|
|
||||||
self.config.property.remove("demoting_error_warning")
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
"source": "Questionary",
|
|
||||||
"errors": self.errors,
|
|
||||||
"warnings": self.warnings,
|
|
||||||
"values": [],
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
def parse_mandatories(self):
|
|
||||||
current_titles = []
|
|
||||||
while True:
|
|
||||||
mandatories = self.config.value.mandatory()
|
|
||||||
if not mandatories:
|
|
||||||
break
|
|
||||||
mandatory = mandatories[0]
|
|
||||||
path = mandatory.path()
|
|
||||||
if "." in path:
|
|
||||||
current_config = self.config
|
|
||||||
for idx, p in enumerate(path.split(".")[0:-1]):
|
|
||||||
current_config = current_config.option(p)
|
|
||||||
if idx < len(current_titles):
|
|
||||||
if current_titles[idx] == p:
|
|
||||||
continue
|
|
||||||
current_titles = current_titles[0:idx]
|
|
||||||
current_titles.append(p)
|
|
||||||
self.print(current_config.description(), idx)
|
|
||||||
self.display_questionary(mandatory, title_level=0)
|
|
||||||
|
|
||||||
def parse(self, config, title_level=0):
|
|
||||||
display_title = True
|
|
||||||
for option in config:
|
|
||||||
if title_level and display_title:
|
|
||||||
self.print(config.description(), title_level)
|
|
||||||
display_title = False
|
|
||||||
if option.isoptiondescription():
|
|
||||||
self.parse(option, title_level + 1)
|
|
||||||
else:
|
|
||||||
self.display_questionary(option, title_level)
|
|
||||||
|
|
||||||
def print(self, title, title_level):
|
|
||||||
qprint(" " * title_level + "📂 " + title, "bold")
|
|
||||||
|
|
||||||
def display_questionary(self, option, title_level):
|
|
||||||
kwargs = {}
|
|
||||||
option_type = option.information.get("type")
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
default = option.value.get()
|
|
||||||
ismulti = option.ismulti()
|
|
||||||
RougailValidator.option = option
|
|
||||||
RougailValidator.option_type = option_type
|
|
||||||
RougailValidator.ismulti = ismulti
|
|
||||||
args = [" " * title_level + "📓 " + option.description()]
|
|
||||||
if "frozen" in option.property.get():
|
|
||||||
self._display_questionary_frozen(args[0], default)
|
|
||||||
return
|
|
||||||
question_funtion = self._dispatcher_questionary(
|
|
||||||
option_type, RougailValidator, kwargs, option, default
|
|
||||||
)
|
|
||||||
ori_default = default
|
|
||||||
if ismulti:
|
|
||||||
kwargs["multiline"] = True
|
|
||||||
if default:
|
|
||||||
kwargs["default"] = "\n".join([str(d) for d in default])
|
|
||||||
elif default is not None:
|
|
||||||
if isinstance(default, (int, float)):
|
|
||||||
default = str(default)
|
|
||||||
kwargs["default"] = default
|
|
||||||
value = RougailValidator().convert_value(
|
|
||||||
question_funtion(*args, **kwargs).ask(), False
|
|
||||||
)
|
|
||||||
if option.owner.isdefault() and value == ori_default:
|
|
||||||
option.value.reset()
|
|
||||||
else:
|
|
||||||
option.value.set(value)
|
|
||||||
|
|
||||||
def _dispatcher_questionary(
|
|
||||||
self, option_type: str, RougailValidator, kwargs: dict, option, default: any
|
|
||||||
) -> callable:
|
|
||||||
if option_type == "choice":
|
|
||||||
RougailValidator.default = default
|
|
||||||
kwargs["choices"] = option.value.list()
|
|
||||||
return select
|
|
||||||
if option_type == "boolean":
|
|
||||||
return confirm
|
|
||||||
if option_type == "secret" and not self.questionary_show_secrets:
|
|
||||||
return password
|
|
||||||
kwargs["validate"] = RougailValidator
|
|
||||||
return text
|
|
||||||
|
|
||||||
def _display_questionary_frozen(self, args: str, default: any) -> None:
|
|
||||||
qprint(" " + args + " " + str(default))
|
|
||||||
|
|
||||||
|
|
||||||
class RougailValidator(Validator):
|
|
||||||
"""Extend Questionary Validator to Rougail needs
|
|
||||||
Be careful it's a singleton
|
|
||||||
"""
|
|
||||||
|
|
||||||
def validate(self, document):
|
|
||||||
"""patch Questionary validate"""
|
|
||||||
return self.convert_value(document.text)
|
|
||||||
|
|
||||||
def convert_value(
|
|
||||||
self,
|
|
||||||
document,
|
|
||||||
set_value=True,
|
|
||||||
) -> any:
|
|
||||||
"""Valid value"""
|
|
||||||
self.set_value = set_value
|
|
||||||
self.document = document
|
|
||||||
self.func = CONVERT_OPTION.get(self.option_type, {}).get("func")
|
|
||||||
convert_func = (
|
|
||||||
self._convert_multi_value if self.ismulti else self._convert_a_value
|
|
||||||
)
|
|
||||||
value = convert_func(document)
|
|
||||||
if self.set_value:
|
|
||||||
self._set_value(value)
|
|
||||||
return value
|
|
||||||
|
|
||||||
def _convert_multi_value(self, value: any) -> list[any]:
|
|
||||||
if self.document is None:
|
|
||||||
return []
|
|
||||||
value = []
|
|
||||||
for val in self.document.strip().split("\n"):
|
|
||||||
val = self._convert_a_value(val)
|
|
||||||
if val is not None:
|
|
||||||
value.append(val)
|
|
||||||
return value
|
|
||||||
|
|
||||||
def _convert_a_value(self, value: any) -> any:
|
|
||||||
if isinstance(value, str):
|
|
||||||
value = value.strip()
|
|
||||||
if value in [None, ""]:
|
|
||||||
return self._convert_empty_value()
|
|
||||||
if not self.func:
|
|
||||||
return value
|
|
||||||
try:
|
|
||||||
return self.func(value)
|
|
||||||
except:
|
|
||||||
msg = _("Not a valid {0}").format(self.option_type)
|
|
||||||
self._raise_validation_error(msg)
|
|
||||||
|
|
||||||
def _convert_empty_value(self) -> any:
|
|
||||||
if self.option_type == "choice":
|
|
||||||
return self.default
|
|
||||||
self._validate_empty_value()
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _set_value(self, value: any) -> None:
|
|
||||||
try:
|
|
||||||
with warnings.catch_warnings(record=True) as warns:
|
|
||||||
self.option.value.set(value)
|
|
||||||
except ValueOptionError as err:
|
|
||||||
self._raise_validation_error(err)
|
|
||||||
for warn in warns:
|
|
||||||
if isinstance(warn.message, ValueErrorWarning):
|
|
||||||
self._raise_validation_error(warn.message)
|
|
||||||
|
|
||||||
def _validate_empty_value(self) -> None:
|
|
||||||
if self.set_value and "mandatory" in self.option.property.get():
|
|
||||||
self._raise_validation_error(_("Value must not be empty"))
|
|
||||||
|
|
||||||
def _raise_validation_error(self, err) -> None:
|
|
||||||
if not isinstance(err, str):
|
|
||||||
err.prefix = ""
|
|
||||||
raise ValidationError(
|
|
||||||
message=str(err),
|
|
||||||
cursor_position=len(self.document),
|
|
||||||
)
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
"""
|
|
||||||
Silique (https://www.silique.fr)
|
|
||||||
Copyright (C) 2025
|
|
||||||
|
|
||||||
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_user_data_questionary",
|
|
||||||
str(Path(__file__).parent / "locale"),
|
|
||||||
fallback=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = t.gettext
|
|
||||||
Binary file not shown.
Loading…
Reference in a new issue