feat: can launch UserDatas twice
This commit is contained in:
parent
fecab8aca6
commit
cbccc8087f
1 changed files with 24 additions and 11 deletions
|
|
@ -41,19 +41,30 @@ class UserDatas:
|
||||||
def __init__(self, config) -> None:
|
def __init__(self, config) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def user_datas(self, user_datas: List[dict]):
|
def user_datas(self,
|
||||||
|
user_datas: List[dict],
|
||||||
|
*,
|
||||||
|
return_values_not_error=False,
|
||||||
|
user_datas_type: str="user_datas",
|
||||||
|
):
|
||||||
self.values = {}
|
self.values = {}
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
self.show_secrets = False
|
self.show_secrets = False
|
||||||
self._populate_values(user_datas)
|
if user_datas_type == "user_datas":
|
||||||
|
self._populate_values(user_datas)
|
||||||
|
else:
|
||||||
|
self.values = user_datas
|
||||||
self._auto_configure_dynamics()
|
self._auto_configure_dynamics()
|
||||||
self._populate_config()
|
self._populate_config()
|
||||||
self._populate_error_warnings()
|
if return_values_not_error:
|
||||||
return {
|
return self.values
|
||||||
"errors": self.errors,
|
else:
|
||||||
"warnings": self.warnings,
|
self._populate_error_warnings()
|
||||||
}
|
return {
|
||||||
|
"errors": self.errors,
|
||||||
|
"warnings": self.warnings,
|
||||||
|
}
|
||||||
|
|
||||||
def _populate_values(self, user_datas):
|
def _populate_values(self, user_datas):
|
||||||
for datas in user_datas:
|
for datas in user_datas:
|
||||||
|
|
@ -215,7 +226,7 @@ class UserDatas:
|
||||||
try:
|
try:
|
||||||
option.value.set(value)
|
option.value.set(value)
|
||||||
option.information.set(
|
option.information.set(
|
||||||
"loaded_from", _("loaded from {0}").format(options["source"])
|
"loaded_from", _("loaded from {0}").format(self.values[path]["source"])
|
||||||
)
|
)
|
||||||
value_is_set = True
|
value_is_set = True
|
||||||
# value is correctly set, remove variable to the set
|
# value is correctly set, remove variable to the set
|
||||||
|
|
@ -287,15 +298,16 @@ class UserDatas:
|
||||||
)
|
)
|
||||||
if option.isfollower():
|
if option.isfollower():
|
||||||
indexes = range(len(value))
|
indexes = range(len(value))
|
||||||
|
values = value
|
||||||
else:
|
else:
|
||||||
indexes = [None]
|
indexes = [None]
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
try:
|
try:
|
||||||
if option.isfollower():
|
if option.isfollower():
|
||||||
val = value[index]
|
value = values[index]
|
||||||
if val is undefined or isinstance(val, CancelParam):
|
if value is undefined or isinstance(value, CancelParam):
|
||||||
continue
|
continue
|
||||||
self.config.option(path, index).value.set(val)
|
self.config.option(path, index).value.set(value)
|
||||||
else:
|
else:
|
||||||
option.value.set(value)
|
option.value.set(value)
|
||||||
except PropertiesOptionError as err:
|
except PropertiesOptionError as err:
|
||||||
|
|
@ -364,6 +376,7 @@ class UserDatas:
|
||||||
).format(
|
).format(
|
||||||
self._display_value(option, value),
|
self._display_value(option, value),
|
||||||
option.description(with_quote=True),
|
option.description(with_quote=True),
|
||||||
|
index,
|
||||||
err,
|
err,
|
||||||
options["source"],
|
options["source"],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue