WIP: Expand the developer documentation #27
11 changed files with 122 additions and 15 deletions
|
|
@ -56,11 +56,12 @@ class UserData:
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
self.invalid_user_data_error = invalid_user_data_error
|
self.invalid_user_data_error = invalid_user_data_error
|
||||||
|
self.unknown_user_data_error = unknown_user_data_error
|
||||||
if self.invalid_user_data_error:
|
if self.invalid_user_data_error:
|
||||||
self.invalids = self.errors
|
self.invalids = self.errors
|
||||||
else:
|
else:
|
||||||
self.invalids = self.warnings
|
self.invalids = self.warnings
|
||||||
if unknown_user_data_error:
|
if self.unknown_user_data_error:
|
||||||
self.unknowns = self.errors
|
self.unknowns = self.errors
|
||||||
else:
|
else:
|
||||||
self.unknowns = self.warnings
|
self.unknowns = self.warnings
|
||||||
|
|
@ -299,7 +300,14 @@ class UserData:
|
||||||
|
|
||||||
def _display_value(self, option, value):
|
def _display_value(self, option, value):
|
||||||
if not self.show_secrets and option.type() == "password":
|
if not self.show_secrets and option.type() == "password":
|
||||||
return "*" * 10
|
if not isinstance(value, list):
|
||||||
|
value = "*" * 10
|
||||||
|
else:
|
||||||
|
value = ["*" * 10 for val in value]
|
||||||
|
if isinstance(value, list):
|
||||||
|
value = display_list(value, add_quote=True)
|
||||||
|
else:
|
||||||
|
value = '"' + value + '"'
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def _populate_error_warnings(self):
|
def _populate_error_warnings(self):
|
||||||
|
|
@ -310,16 +318,24 @@ class UserData:
|
||||||
option = self.config.forcepermissive.option(path)
|
option = self.config.forcepermissive.option(path)
|
||||||
else:
|
else:
|
||||||
option = self.config.option(path)
|
option = self.config.option(path)
|
||||||
|
if option.issymlinkoption():
|
||||||
|
err = _('it\'s a symlink option so we cannot set the value {0}').format(self._display_value(option, value))
|
||||||
|
if self.invalid_user_data_error:
|
||||||
|
msg = _('{0}, it has been loading from {1}').format(err, options["source"])
|
||||||
|
else:
|
||||||
|
msg = _('{0}, it will be ignored when loading from {1}').format(err, options["source"])
|
||||||
|
self.unknowns.append({msg: option._subconfig})
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
if option.isoptiondescription():
|
if option.isoptiondescription():
|
||||||
if value:
|
if value:
|
||||||
if self.invalid_user_data_error:
|
if self.invalid_user_data_error:
|
||||||
msg = _(
|
msg = _(
|
||||||
'is a family so we cannot set the value "{0}", it has been loading from {1}'
|
'it\'s a family so we cannot set the value {0}, it has been loading from {1}'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
msg = _(
|
msg = _(
|
||||||
'is a family so we cannot set the value "{0}", it will be ignored when loading from {1}'
|
'it\'s a family so we cannot set the value {0}, it will be ignored when loading from {1}'
|
||||||
)
|
)
|
||||||
self.invalids.append({msg.format(
|
self.invalids.append({msg.format(
|
||||||
self._display_value(option, value),
|
self._display_value(option, value),
|
||||||
|
|
@ -339,7 +355,7 @@ class UserData:
|
||||||
continue
|
continue
|
||||||
except AttributeOptionError as err:
|
except AttributeOptionError as err:
|
||||||
if err.code == "option-not-found":
|
if err.code == "option-not-found":
|
||||||
if self.invalid_user_data_error:
|
if self.unknown_user_data_error:
|
||||||
msg = _(
|
msg = _(
|
||||||
'variable or family "{0}" does not exist, it has been loading from {1}'
|
'variable or family "{0}" does not exist, it has been loading from {1}'
|
||||||
)
|
)
|
||||||
|
|
@ -392,7 +408,7 @@ class UserData:
|
||||||
display_name = option.description(with_quote=True)
|
display_name = option.description(with_quote=True)
|
||||||
if index is not None:
|
if index is not None:
|
||||||
if path == err_path:
|
if path == err_path:
|
||||||
if self.invalid_user_data_error:
|
if self.unknown_user_data_error:
|
||||||
msg = _(
|
msg = _(
|
||||||
'variable {0} at index "{1}" is {2}, it has been loading from {3}'
|
'variable {0} at index "{1}" is {2}, it has been loading from {3}'
|
||||||
)
|
)
|
||||||
|
|
@ -409,7 +425,7 @@ class UserData:
|
||||||
): option._subconfig}
|
): option._subconfig}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if self.invalid_user_data_error:
|
if self.unknown_user_data_error:
|
||||||
msg = _(
|
msg = _(
|
||||||
'family {0} is {1}, {2} at index "{3}", it has been loading from {4}'
|
'family {0} is {1}, {2} at index "{3}", it has been loading from {4}'
|
||||||
)
|
)
|
||||||
|
|
@ -428,7 +444,7 @@ class UserData:
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if path == err_path:
|
if path == err_path:
|
||||||
if self.invalid_user_data_error:
|
if self.unknown_user_data_error:
|
||||||
msg = _(
|
msg = _(
|
||||||
"variable has propery {0}, it has been loading from {1}"
|
"variable has propery {0}, it has been loading from {1}"
|
||||||
)
|
)
|
||||||
|
|
@ -442,7 +458,7 @@ class UserData:
|
||||||
): option._subconfig}
|
): option._subconfig}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if self.invalid_user_data_error:
|
if self.unknown_user_data_error:
|
||||||
msg = _(
|
msg = _(
|
||||||
"family {0} has property {1}, so cannot access to {2}, it has been loading from {3}"
|
"family {0} has property {1}, so cannot access to {2}, it has been loading from {3}"
|
||||||
)
|
)
|
||||||
|
|
@ -459,11 +475,29 @@ class UserData:
|
||||||
): option._subconfig}
|
): option._subconfig}
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
if self.unknown_user_data_error:
|
||||||
|
msg = _(
|
||||||
|
"{0}, it has been loading from {1}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
msg = _(
|
||||||
|
"{0}, it will be ignored when loading from {1}"
|
||||||
|
)
|
||||||
self.unknowns.append({
|
self.unknowns.append({
|
||||||
_("{0} in {1}").format(err, options["source"]): option._subconfig}
|
msg.format(err, options["source"]): option._subconfig}
|
||||||
)
|
)
|
||||||
except LeadershipError as err:
|
except LeadershipError as err:
|
||||||
self.unknowns.append({_("{0} in {1}").format(err, options["source"]): option._subconfig})
|
if self.unknown_user_data_error:
|
||||||
|
msg = _(
|
||||||
|
"{0}, it has been loading from {1}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
msg = _(
|
||||||
|
"{0}, it will be ignored when loading from {1}"
|
||||||
|
)
|
||||||
|
self.unknowns.append({
|
||||||
|
msg.format(err, options["source"]): option._subconfig}
|
||||||
|
)
|
||||||
except ConfigError as err:
|
except ConfigError as err:
|
||||||
err.prefix = ""
|
err.prefix = ""
|
||||||
if self.invalid_user_data_error:
|
if self.invalid_user_data_error:
|
||||||
|
|
@ -474,7 +508,7 @@ class UserData:
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
err.prefix = ""
|
err.prefix = ""
|
||||||
type_ = option.type(translation=True)
|
type_ = option.type(translation=True)
|
||||||
msg = _('the value "{0}" is an invalid {1}, {2}').format(
|
msg = _('the value {0} is an invalid {1}, {2}').format(
|
||||||
self._display_value(option, value),
|
self._display_value(option, value),
|
||||||
type_,
|
type_,
|
||||||
err,
|
err,
|
||||||
|
|
|
||||||
10
tests/dictionaries/20_7help_family/makedict/after.json
Normal file
10
tests/dictionaries/20_7help_family/makedict/after.json
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.family1.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.family2.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
||||||
4
tests/dictionaries/20_7help_family/makedict/base.json
Normal file
4
tests/dictionaries/20_7help_family/makedict/base.json
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.family1.var": null,
|
||||||
|
"rougail.family2.var": null
|
||||||
|
}
|
||||||
10
tests/dictionaries/20_7help_family/makedict/before.json
Normal file
10
tests/dictionaries/20_7help_family/makedict/before.json
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"rougail.family1.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
"rougail.family2.var": {
|
||||||
|
"owner": "default",
|
||||||
|
"value": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
["rougail.family1.var", "rougail.family2.var"]
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.family1.var": null,
|
||||||
|
"rougail.family2.var": null
|
||||||
|
}
|
||||||
18
tests/dictionaries/20_7help_family/tiramisu/base.py
Normal file
18
tests/dictionaries/20_7help_family/tiramisu/base.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
from re import compile as re_compile
|
||||||
|
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||||
|
load_functions('../rougail-tests/funcs/test.py')
|
||||||
|
try:
|
||||||
|
groups.namespace
|
||||||
|
except:
|
||||||
|
groups.addgroup('namespace')
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
option_3 = StrOption(name="var", doc="var", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'type': 'string'})
|
||||||
|
optiondescription_2 = OptionDescription(name="family1", doc="the first family", children=[option_3], properties=frozenset({"basic"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'help': 'Multi line\n\nHelp\n\nWith useful information'})
|
||||||
|
option_5 = StrOption(name="var", doc="var", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'type': 'string'})
|
||||||
|
optiondescription_4 = OptionDescription(name="family2", doc="the second family", children=[option_5], properties=frozenset({"basic"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'help': 'Multi line\nHelp\nWith useful information'})
|
||||||
|
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[optiondescription_2, optiondescription_4], properties=frozenset({"basic"}))
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
||||||
17
tests/dictionaries/20_7help_family/tiramisu/no_namespace.py
Normal file
17
tests/dictionaries/20_7help_family/tiramisu/no_namespace.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
from tiramisu import *
|
||||||
|
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||||
|
from re import compile as re_compile
|
||||||
|
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||||
|
load_functions('../rougail-tests/funcs/test.py')
|
||||||
|
try:
|
||||||
|
groups.namespace
|
||||||
|
except:
|
||||||
|
groups.addgroup('namespace')
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||||
|
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||||
|
option_2 = StrOption(name="var", doc="var", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'type': 'string'})
|
||||||
|
optiondescription_1 = OptionDescription(name="family1", doc="the first family", children=[option_2], properties=frozenset({"basic"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'help': 'Multi line\n\nHelp\n\nWith useful information'})
|
||||||
|
option_4 = StrOption(name="var", doc="var", properties=frozenset({"basic", "mandatory"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'type': 'string'})
|
||||||
|
optiondescription_3 = OptionDescription(name="family2", doc="the second family", children=[option_4], properties=frozenset({"basic"}), informations={'ymlfiles': ['../rougail-tests/structures/20_7help_family/rougail/00-base.yml'], 'help': 'Multi line\nHelp\nWith useful information'})
|
||||||
|
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_3])
|
||||||
|
|
@ -111,7 +111,10 @@ def load_rougail_object(test_dir, rougailconfig, multi=False, namespace=False):
|
||||||
if namespace is False and not multi:
|
if namespace is False and not multi:
|
||||||
return None
|
return None
|
||||||
rougailconfig['extra_namespaces'] = extra_namespaces
|
rougailconfig['extra_namespaces'] = extra_namespaces
|
||||||
rougailconfig['tiramisu_cache'] = get_tiramisu_filename(test_dir, 'tmp', multi, namespace)
|
try:
|
||||||
|
rougailconfig['tiramisu_cache'] = get_tiramisu_filename(test_dir, 'tmp', multi, namespace)
|
||||||
|
except:
|
||||||
|
rougailconfig['cli.tiramisu_cache'] = get_tiramisu_filename(test_dir, 'tmp', multi, namespace)
|
||||||
rougailconfig['custom_types']['custom'] = CustomOption
|
rougailconfig['custom_types']['custom'] = CustomOption
|
||||||
return Rougail(rougailconfig)
|
return Rougail(rougailconfig)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,10 @@ def test_personalize_mode():
|
||||||
rougailconfig['modes_level'] = ['level1', 'level2']
|
rougailconfig['modes_level'] = ['level1', 'level2']
|
||||||
rougailconfig['default_variable_mode'] = 'level1'
|
rougailconfig['default_variable_mode'] = 'level1'
|
||||||
rougailconfig['default_family_mode'] = 'level1'
|
rougailconfig['default_family_mode'] = 'level1'
|
||||||
rougailconfig['tiramisu_cache'] = None
|
try:
|
||||||
|
rougailconfig['tiramisu_cache'] = None
|
||||||
|
except:
|
||||||
|
rougailconfig['cli.tiramisu_cache'] = None
|
||||||
eolobj = Rougail(rougailconfig=rougailconfig)
|
eolobj = Rougail(rougailconfig=rougailconfig)
|
||||||
eolobj.run()
|
eolobj.run()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,10 @@ def type_variable(test_name):
|
||||||
rougailconfig = RougailConfig.copy()
|
rougailconfig = RougailConfig.copy()
|
||||||
rougailconfig['types'] = [f'tests/types/types/{test_name}']
|
rougailconfig['types'] = [f'tests/types/types/{test_name}']
|
||||||
rougailconfig['main_structural_directories'] = [f'tests/types/structures/{ test_name }']
|
rougailconfig['main_structural_directories'] = [f'tests/types/structures/{ test_name }']
|
||||||
rougailconfig['tiramisu_cache'] = str(tmp_file)
|
try:
|
||||||
|
rougailconfig['tiramisu_cache'] = str(tmp_file)
|
||||||
|
except:
|
||||||
|
rougailconfig['cli.tiramisu_cache'] = str(tmp_file)
|
||||||
rougail = Rougail(rougailconfig=rougailconfig)
|
rougail = Rougail(rougailconfig=rougailconfig)
|
||||||
config = rougail.run()
|
config = rougail.run()
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue