renaming to environment

This commit is contained in:
gwen 2024-09-04 16:50:15 +02:00
parent 34d16cfb37
commit ab1f1bb5c3
4 changed files with 25 additions and 26 deletions

View file

@ -1,2 +1,2 @@
from .data import RougailUserDataQuestionary
__all__ = ('RougailUserDataQuestionary',)
from .data import RougailUserEnvironment
__all__ = ('RougailUserEnvironment',)

6
cli.py
View file

@ -1,5 +1,5 @@
"""
Cli code for Rougail-user-data-questionary
Cli code for Rougail-user-data-environment
Silique (https://www.silique.fr)
Copyright (C) 2024
@ -20,14 +20,14 @@ 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 .data import RougailUserDataEnvironment
def run(rougailconfig,
config,
user_datas,
):
RougailUserDataQuestionary(config,
RougailUserDataEnvironment(config,
rougailconfig=rougailconfig,
).run()

View file

@ -1,5 +1,5 @@
"""
Config file for Rougail-user-data-questionary
Config file for Rougail-user-data-environment
Silique (https://www.silique.fr)
Copyright (C) 2024
@ -24,12 +24,12 @@ def get_rougail_config(*,
backward_compatibility=True,
) -> dict:
options = """
questionary:
environment:
description: Define value interactivly
disabled:
type: jinja
jinja: |
{% if 'questionary' not in step.user_data %}
{% if 'environment' not in step.user_data %}
disabled
{% endif %}
mandatory:
@ -47,10 +47,10 @@ questionary:
variable: __.exporter.show_secrets
optional: true
"""
return {'name': 'questionary',
return {'name': 'environment',
'process': 'user data',
'options': options,
'level': 60,
'level': 70, # FIXME : what for ?
}

31
data.py
View file

@ -2,19 +2,19 @@
"""
Silique (https://www.silique.fr)
Copyright (C) 2024
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
@ -22,9 +22,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from rougail.object_model import CONVERT_OPTION
from rougail.config import RougailConfig
from tiramisu.error import ValueOptionError
from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint
class RougailUserDataQuestionary:
class RougailUserDataEnvironment:
def __init__(self,
config: 'Config',
*,
@ -34,19 +33,19 @@ class RougailUserDataQuestionary:
if rougailconfig is None:
rougailconfig = RougailConfig
user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data:
user_data.append('questionary')
if 'environment' not in user_data:
user_data.append('environment')
rougailconfig['step.user_data'] = user_data
user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data:
raise Exception('questionary is not set in step.user_data')
if 'environment' not in user_data:
raise Exception('environment is not set in step.user_data')
self.rougailconfig = rougailconfig
self.errors = []
self.warnings = []
def run(self):
self.config.property.read_write()
if self.rougailconfig['questionary.mandatory']:
if self.rougailconfig['environment.mandatory']:
current_titles = []
while True:
mandatories = self.config.value.mandatory()
@ -64,7 +63,7 @@ class RougailUserDataQuestionary:
current_titles = current_titles[0:idx]
current_titles.append(p)
self.print(current_config.description(), idx)
self.display_questionary(mandatory)
self.display_environment(mandatory)
else:
self.parse(self.config)
self.config.property.read_only()
@ -75,12 +74,12 @@ class RougailUserDataQuestionary:
self.print(option.description(), title_level)
self.parse(option, title_level + 1)
else:
self.display_questionary(option)
self.display_environment(option)
def print(self, title, title_level):
qprint(' ' * title_level + '📂 ' + title, 'bold')
def display_questionary(self, option):
def display_environment(self, option):
kwargs = {}
option_type = option.information.get('type')
isdefault = option.owner.isdefault()
@ -99,7 +98,7 @@ class RougailUserDataQuestionary:
kwargs['choices'] = option.value.list()
elif option_type == 'boolean':
question_funtion = confirm
elif option_type == 'secret' and not self.rougailconfig['questionary.show_secrets']:
elif option_type == 'secret' and not self.rougailconfig['environment.show_secrets']:
question_funtion = password
else:
question_funtion = text
@ -131,7 +130,7 @@ class RougailValidator(Validator):
else:
value = []
if document is not None:
for val in document.strip().split('\n'):
for val in document.strip().split('\n'):
val = self._convert_a_value(val, document, validate)
if val is not None:
value.append(val)