82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
"""
|
|
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 General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Mtools 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 Mtools. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
from rougail.user_datas import UserDatas
|
|
|
|
|
|
def load(rougailconfig: "RougailConfig",
|
|
yaml_file: str=None,
|
|
env_prefix: str=None,
|
|
commandline: bool=False,
|
|
_arguments=None,
|
|
_add_help=True,
|
|
_generate=True
|
|
):
|
|
if _generate:
|
|
rougailconfig.generate_config()
|
|
cmd_config = rougailconfig.config
|
|
origin_prop = cmd_config.property.exportation()
|
|
cmd_config.property.read_write()
|
|
user_datas = []
|
|
if yaml_file:
|
|
user_datas.extend(from_yaml(cmd_config, yaml_file))
|
|
if env_prefix:
|
|
user_datas.extend(from_env(cmd_config, env_prefix))
|
|
if commandline:
|
|
user_datas.extend(from_cmdline(cmd_config, _arguments, _add_help))
|
|
user_data = UserDatas(cmd_config).user_datas(user_datas)
|
|
cmd_config.property.importation(origin_prop)
|
|
return user_data
|
|
|
|
|
|
def from_yaml(cmd_config, yaml_file):
|
|
from rougail.user_data_yaml import RougailUserDataYaml
|
|
fake_rougail_config = {
|
|
"step.user_data": ["yaml"],
|
|
"yaml.filename": [yaml_file],
|
|
"yaml.file_with_secrets": "all",
|
|
}
|
|
return RougailUserDataYaml(cmd_config,
|
|
rougailconfig=fake_rougail_config,
|
|
).run()
|
|
|
|
|
|
def from_env(cmd_config, env_prefix):
|
|
from rougail.user_data_environment import RougailUserDataEnvironment
|
|
fake_rougail_config = {
|
|
"main_namespace": None,
|
|
"step.user_data": ["environment"],
|
|
"environment.default_environment_name": env_prefix,
|
|
"environment.custom_separator": None,
|
|
}
|
|
return RougailUserDataEnvironment(
|
|
cmd_config,
|
|
rougailconfig=fake_rougail_config,
|
|
).run()
|
|
|
|
|
|
def from_cmdline(cmd_config, arguments, add_help):
|
|
from rougail.user_data_commandline import RougailUserDataCommandline
|
|
fake_rougail_config = {
|
|
"step.user_data": ["commandline"],
|
|
}
|
|
return RougailUserDataCommandline(cmd_config,
|
|
rougailconfig=fake_rougail_config,
|
|
short_name_max_len=2,
|
|
arguments=arguments,
|
|
add_help=add_help,
|
|
).run()
|