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 from .data import RougailUserEnvironment
__all__ = ('RougailUserDataQuestionary',) __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) Silique (https://www.silique.fr)
Copyright (C) 2024 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 along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from .data import RougailUserDataQuestionary from .data import RougailUserDataEnvironment
def run(rougailconfig, def run(rougailconfig,
config, config,
user_datas, user_datas,
): ):
RougailUserDataQuestionary(config, RougailUserDataEnvironment(config,
rougailconfig=rougailconfig, rougailconfig=rougailconfig,
).run() ).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) Silique (https://www.silique.fr)
Copyright (C) 2024 Copyright (C) 2024
@ -24,12 +24,12 @@ def get_rougail_config(*,
backward_compatibility=True, backward_compatibility=True,
) -> dict: ) -> dict:
options = """ options = """
questionary: environment:
description: Define value interactivly description: Define value interactivly
disabled: disabled:
type: jinja type: jinja
jinja: | jinja: |
{% if 'questionary' not in step.user_data %} {% if 'environment' not in step.user_data %}
disabled disabled
{% endif %} {% endif %}
mandatory: mandatory:
@ -47,10 +47,10 @@ questionary:
variable: __.exporter.show_secrets variable: __.exporter.show_secrets
optional: true optional: true
""" """
return {'name': 'questionary', return {'name': 'environment',
'process': 'user data', 'process': 'user data',
'options': options, 'options': options,
'level': 60, 'level': 70, # FIXME : what for ?
} }

31
data.py
View file

@ -2,19 +2,19 @@
""" """
Silique (https://www.silique.fr) Silique (https://www.silique.fr)
Copyright (C) 2024 Copyright (C) 2024
distribued with GPL-2 or later license distribued with GPL-2 or later license
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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.object_model import CONVERT_OPTION
from rougail.config import RougailConfig from rougail.config import RougailConfig
from tiramisu.error import ValueOptionError from tiramisu.error import ValueOptionError
from questionary import text, select, confirm, password, Validator, ValidationError, print as qprint
class RougailUserDataQuestionary: class RougailUserDataEnvironment:
def __init__(self, def __init__(self,
config: 'Config', config: 'Config',
*, *,
@ -34,19 +33,19 @@ class RougailUserDataQuestionary:
if rougailconfig is None: if rougailconfig is None:
rougailconfig = RougailConfig rougailconfig = RougailConfig
user_data = rougailconfig['step.user_data'] user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data: if 'environment' not in user_data:
user_data.append('questionary') user_data.append('environment')
rougailconfig['step.user_data'] = user_data rougailconfig['step.user_data'] = user_data
user_data = rougailconfig['step.user_data'] user_data = rougailconfig['step.user_data']
if 'questionary' not in user_data: if 'environment' not in user_data:
raise Exception('questionary is not set in step.user_data') raise Exception('environment is not set in step.user_data')
self.rougailconfig = rougailconfig self.rougailconfig = rougailconfig
self.errors = [] self.errors = []
self.warnings = [] self.warnings = []
def run(self): def run(self):
self.config.property.read_write() self.config.property.read_write()
if self.rougailconfig['questionary.mandatory']: if self.rougailconfig['environment.mandatory']:
current_titles = [] current_titles = []
while True: while True:
mandatories = self.config.value.mandatory() mandatories = self.config.value.mandatory()
@ -64,7 +63,7 @@ class RougailUserDataQuestionary:
current_titles = current_titles[0:idx] current_titles = current_titles[0:idx]
current_titles.append(p) current_titles.append(p)
self.print(current_config.description(), idx) self.print(current_config.description(), idx)
self.display_questionary(mandatory) self.display_environment(mandatory)
else: else:
self.parse(self.config) self.parse(self.config)
self.config.property.read_only() self.config.property.read_only()
@ -75,12 +74,12 @@ class RougailUserDataQuestionary:
self.print(option.description(), title_level) self.print(option.description(), title_level)
self.parse(option, title_level + 1) self.parse(option, title_level + 1)
else: else:
self.display_questionary(option) self.display_environment(option)
def print(self, title, title_level): def print(self, title, title_level):
qprint(' ' * title_level + '📂 ' + title, 'bold') qprint(' ' * title_level + '📂 ' + title, 'bold')
def display_questionary(self, option): def display_environment(self, option):
kwargs = {} kwargs = {}
option_type = option.information.get('type') option_type = option.information.get('type')
isdefault = option.owner.isdefault() isdefault = option.owner.isdefault()
@ -99,7 +98,7 @@ class RougailUserDataQuestionary:
kwargs['choices'] = option.value.list() kwargs['choices'] = option.value.list()
elif option_type == 'boolean': elif option_type == 'boolean':
question_funtion = confirm 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 question_funtion = password
else: else:
question_funtion = text question_funtion = text
@ -131,7 +130,7 @@ class RougailValidator(Validator):
else: else:
value = [] value = []
if document is not None: 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) val = self._convert_a_value(val, document, validate)
if val is not None: if val is not None:
value.append(val) value.append(val)