diff --git a/src/rougail/user-data-environment/config.py b/src/rougail/user-data-environment/config.py index aedf23e..e4344c6 100644 --- a/src/rougail/user-data-environment/config.py +++ b/src/rougail/user-data-environment/config.py @@ -20,6 +20,11 @@ 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 """ + +"rougail environment variable prefix" +rougail_environment_var = "ROUGAIL_" + + def get_rougail_config(*, backward_compatibility=True, ) -> dict: diff --git a/src/rougail/user-data-environment/data.py b/src/rougail/user-data-environment/data.py index c0b7c78..abb8136 100644 --- a/src/rougail/user-data-environment/data.py +++ b/src/rougail/user-data-environment/data.py @@ -87,8 +87,22 @@ class RougailUserDataEnvironment: ismulti = option.ismulti() type_obj = None type_obj = CONVERT_OPTION.get(option_type, {}).get("func") - print(dir(option)) - option.value.set(["78", "52"]) + + from .helper import get_rougail_environment_var, get_rougail_environment_dict + rougail_environment_var = get_rougail_environment_var() + option_name = option.path() + if option_name in rougail_environment_var: + option.value.set(get_rougail_environment_dict()[option_name]) + #option.value.set(["78", "52"]) + # TODO + # - tester les var commençant par ROUGAIL_ + # 'ROUGAIL_' + # tester si c'est une multi + # le CONVERT_TYPE ne marchera pas si c'est une multi + # récupérer le nam de l'option pour voir si elle est dans l'env + + + #RougailValidator.option = option #RougailValidator.option_type = {'type': option_type, # 'func': type_obj, diff --git a/src/rougail/user-data-environment/helper.py b/src/rougail/user-data-environment/helper.py new file mode 100644 index 0000000..e09d1ae --- /dev/null +++ b/src/rougail/user-data-environment/helper.py @@ -0,0 +1,38 @@ +""" +Helper file for Rougail-user-data-environment + +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 +""" + +import os + +from .config import rougail_environment_var + +def get_rougail_environment_var(): + "lists all rougail environment variables (that is, wich startswith ROUGAIL_)" + all_envvar = os.environ + return [envvar.replace(rougail_environment_var, '') for envvar in all_envvar if envvar.startswith(rougail_environment_var)] + +def get_rougail_environment_dict(): + "rougail environment variables as a key/value dict" + rougail_environment_dict = dict() + for var in get_rougail_environment_var(): + rougail_environment_dict[var] = os.environ[rougail_environment_var + var] + return rougail_environment_dict