activate is not a true boolean
This commit is contained in:
parent
f5f68f3bc8
commit
0a8be9a355
19 changed files with 87 additions and 48 deletions
|
@ -41,14 +41,15 @@ class ConditionAnnotator:
|
|||
objectspace,
|
||||
):
|
||||
self.objectspace = objectspace
|
||||
self.force_service_value = {}
|
||||
if hasattr(objectspace.space, 'variables'):
|
||||
self.convert_auto_freeze()
|
||||
if not hasattr(objectspace.space, 'constraints') or \
|
||||
not hasattr(self.objectspace.space.constraints, 'condition'):
|
||||
return
|
||||
self.convert_condition_target()
|
||||
self.convert_xxxlist_to_variable()
|
||||
self.check_condition_fallback()
|
||||
self.convert_xxxlist_to_variable()
|
||||
self.convert_condition_source()
|
||||
self.check_choice_option_condition()
|
||||
self.remove_condition_with_empty_target()
|
||||
|
@ -133,31 +134,6 @@ class ConditionAnnotator:
|
|||
for index in remove_targets:
|
||||
condition.target.pop(index)
|
||||
|
||||
|
||||
def convert_xxxlist_to_variable(self):
|
||||
"""transform *list to variable or family
|
||||
"""
|
||||
for condition in self.objectspace.space.constraints.condition:
|
||||
new_targets = []
|
||||
remove_targets = []
|
||||
for target_idx, target in enumerate(condition.target):
|
||||
if target.type.endswith('list'):
|
||||
listname = target.type
|
||||
listvars = self.objectspace.list_conditions.get(listname,
|
||||
{}).get(target.name)
|
||||
if listvars:
|
||||
for listvar in listvars:
|
||||
type_ = 'variable'
|
||||
new_target = self.objectspace.target(listvar.xmlfiles)
|
||||
new_target.type = type_
|
||||
new_target.name = listvar
|
||||
new_targets.append(new_target)
|
||||
remove_targets.append(target_idx)
|
||||
remove_targets.sort(reverse=True)
|
||||
for target_idx in remove_targets:
|
||||
condition.target.pop(target_idx)
|
||||
condition.target.extend(new_targets)
|
||||
|
||||
def check_condition_fallback(self):
|
||||
"""a condition with a fallback **and** the source variable doesn't exist
|
||||
"""
|
||||
|
@ -187,8 +163,11 @@ class ConditionAnnotator:
|
|||
"""
|
||||
actions = self.get_actions_from_condition(condition.name)
|
||||
for target in condition.target:
|
||||
leader_or_var, variables = self._get_family_variables_from_target(target)
|
||||
main_action = actions[0]
|
||||
if target.type.endswith('list'):
|
||||
self.force_service_value[target.name] = main_action != 'disabled'
|
||||
continue
|
||||
leader_or_var, variables = self._get_family_variables_from_target(target)
|
||||
setattr(leader_or_var, main_action, True)
|
||||
for action in actions[1:]:
|
||||
for variable in variables:
|
||||
|
@ -224,6 +203,65 @@ class ConditionAnnotator:
|
|||
return variable, list(variable.variable.values())
|
||||
return variable, []
|
||||
|
||||
def convert_xxxlist_to_variable(self):
|
||||
"""transform *list to variable or family
|
||||
"""
|
||||
fills = {}
|
||||
for condition in self.objectspace.space.constraints.condition:
|
||||
remove_targets = []
|
||||
for target_idx, target in enumerate(condition.target):
|
||||
if target.type.endswith('list'):
|
||||
listname = target.type
|
||||
listvars = self.objectspace.list_conditions.get(listname,
|
||||
{}).get(target.name)
|
||||
if listvars:
|
||||
for listvar in listvars:
|
||||
if target.name in self.force_service_value:
|
||||
listvar.default = self.force_service_value[target.name]
|
||||
continue
|
||||
value = condition.name != 'disabled_if_in'
|
||||
if len(condition.param) != 1:
|
||||
xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles)
|
||||
msg = _(f'a condition with "{listname}" can only have '
|
||||
f'only have only on param')
|
||||
raise DictConsistencyError(msg, 35) from err
|
||||
if listvar.path in fills:
|
||||
fill = fills[listvar.path]
|
||||
fill.index += 1
|
||||
else:
|
||||
fill = self.objectspace.fill(target.xmlfiles)
|
||||
fill.target = listvar.path
|
||||
fill.name = 'calc_value'
|
||||
fill.namespace = 'services'
|
||||
fill.index = 0
|
||||
if not hasattr(self.objectspace.space, 'constraints'):
|
||||
self.objectspace.space.constraints = self.objectspace.constraints(elt.xmlfiles)
|
||||
if not hasattr(self.objectspace.space.constraints, 'fill'):
|
||||
self.objectspace.space.constraints.fill = []
|
||||
self.objectspace.space.constraints.fill.append(fill)
|
||||
fills[listvar.path] = fill
|
||||
param1 = self.objectspace.param(target.xmlfiles)
|
||||
param1.text = value
|
||||
param1.type = 'boolean'
|
||||
param2 = self.objectspace.param(target.xmlfiles)
|
||||
param2.name = 'default'
|
||||
param2.text = not value
|
||||
param2.type = 'boolean'
|
||||
fill.param = [param1, param2]
|
||||
param3 = self.objectspace.param(target.xmlfiles)
|
||||
param3.name = f'condition_{fill.index}'
|
||||
param3.type = 'variable'
|
||||
param3.text = condition.source
|
||||
fill.param.append(param3)
|
||||
param4 = self.objectspace.param(target.xmlfiles)
|
||||
param4.name = f'expected_{fill.index}'
|
||||
param4.text = getattr(condition.param[0], 'text', None)
|
||||
fill.param.append(param4)
|
||||
remove_targets.append(target_idx)
|
||||
remove_targets.sort(reverse=True)
|
||||
for target_idx in remove_targets:
|
||||
condition.target.pop(target_idx)
|
||||
|
||||
def convert_condition_source(self):
|
||||
"""remove condition for ChoiceOption that don't have param
|
||||
"""
|
||||
|
|
|
@ -79,7 +79,10 @@ class FillAnnotator:
|
|||
value = self.objectspace.value(fill.xmlfiles)
|
||||
value.type = 'calculation'
|
||||
value.name = fill.name
|
||||
variable.value = [value]
|
||||
if variable.namespace == 'services':
|
||||
variable.default = value
|
||||
else:
|
||||
variable.value = [value]
|
||||
|
||||
# manage params
|
||||
if not hasattr(fill, 'param'):
|
||||
|
|
|
@ -123,8 +123,6 @@ class ServiceAnnotator:
|
|||
elt.xmlfiles,
|
||||
)
|
||||
family.variable = []
|
||||
# FIXME ne devrait pas etre True par défaut
|
||||
# devrait etre un calcule
|
||||
activate_obj = self._generate_element('boolean',
|
||||
'activate',
|
||||
True,
|
||||
|
|
|
@ -365,7 +365,7 @@ class CreoleTemplateEngine:
|
|||
filename = fill['source']
|
||||
if not isfile(filename): # pragma: no cover
|
||||
raise FileNotFound(_(f"File {filename} does not exist."))
|
||||
if fill.get('activate', False):
|
||||
if fill['activate']:
|
||||
self.instance_file(fill,
|
||||
tmp_dir,
|
||||
dest_dir,
|
||||
|
|
|
@ -312,7 +312,7 @@ class Variable(Common):
|
|||
if value is not None:
|
||||
value = self.convert_str(value)
|
||||
return f"ParamValue({value})"
|
||||
if param.type == 'number':
|
||||
if param.type in ['number', 'boolean']:
|
||||
return f'ParamValue({param.text})'
|
||||
if param.type == 'variable':
|
||||
return self.build_param(param, function)
|
||||
|
@ -320,7 +320,7 @@ class Variable(Common):
|
|||
return f'ParamInformation("{param.text}", None)'
|
||||
if param.type == 'suffix':
|
||||
return 'ParamSuffix()'
|
||||
return '' # pragma: no cover
|
||||
raise Exception(f'unknown type {param.type}') # pragma: no cover
|
||||
|
||||
@staticmethod
|
||||
def build_param(param,
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/etc/file")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("oui")})))
|
||||
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rougail.general.condition": "oui", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/etc/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true}
|
||||
{"rougail.general.condition": "oui", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/etc/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": false}
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/etc/file")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("oui")})))
|
||||
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file1")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file1")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("oui")})))
|
||||
option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_18 = StrOption(name="group", doc="group", default="root")
|
||||
option_19 = StrOption(name="mode", doc="mode", default="0644")
|
||||
|
@ -31,7 +31,7 @@ option_20 = StrOption(name="name", doc="name", default="/tmp/file2")
|
|||
option_21 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_22 = StrOption(name="source", doc="source", default="file2")
|
||||
option_23 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_24 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')}))}))
|
||||
option_24 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("oui")})))
|
||||
option_17 = OptionDescription(name="file2", doc="file2", children=[option_18, option_19, option_20, option_21, option_22, option_23, option_24])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9, option_17])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true}
|
||||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": false}
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('unpossible'), 'reverse_condition': ParamValue(True)}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("unpossible")})))
|
||||
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true}
|
||||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": false}
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('unpossible'), 'reverse_condition': ParamValue(True)}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("unpossible")})))
|
||||
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true}
|
||||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": false}
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('unpossible'), 'reverse_condition': ParamValue(True)})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_5, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5, notraisepropertyerror=False, todict=False), 'expected_1': ParamValue("oui")})))
|
||||
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true}
|
||||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/tmp/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": false}
|
||||
|
|
|
@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file")
|
|||
option_13 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_14 = StrOption(name="source", doc="source", default="file")
|
||||
option_15 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('statique'), 'reverse_condition': ParamValue(True)}))}))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, notraisepropertyerror=False, todict=False), 'expected_0': ParamValue("statique")})))
|
||||
option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16])
|
||||
option_8 = OptionDescription(name="files", doc="files", children=[option_9])
|
||||
option_7 = OptionDescription(name="test", doc="test", children=[option_8])
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"rougail.general.mode_conteneur_actif": "non", "rougail.general.condition": "non", "services.test.files.file1.group": "root", "services.test.files.file1.mode": "0644", "services.test.files.file1.name": "/tmp/file1", "services.test.files.file1.owner": "root", "services.test.files.file1.source": "file1", "services.test.files.file1.templating": true}
|
||||
{"rougail.general.mode_conteneur_actif": "non", "rougail.general.condition": "non", "services.test.files.file1.group": "root", "services.test.files.file1.mode": "0644", "services.test.files.file1.name": "/tmp/file1", "services.test.files.file1.owner": "root", "services.test.files.file1.source": "file1", "services.test.files.file1.templating": true, "services.test.files.file1.activate": false}
|
||||
|
|
|
@ -22,7 +22,7 @@ option_11 = StrOption(name="name", doc="name", default="/tmp/file1")
|
|||
option_12 = StrOption(name="owner", doc="owner", default="root")
|
||||
option_13 = StrOption(name="source", doc="source", default="file1")
|
||||
option_14 = BoolOption(name="templating", doc="templating", default=True)
|
||||
option_15 = BoolOption(name="activate", doc="activate", default=True, properties=frozenset({"disabled"}))
|
||||
option_15 = BoolOption(name="activate", doc="activate", default=False)
|
||||
option_8 = OptionDescription(name="file1", doc="file1", children=[option_9, option_10, option_11, option_12, option_13, option_14, option_15])
|
||||
option_7 = OptionDescription(name="files", doc="files", children=[option_8])
|
||||
option_6 = OptionDescription(name="test", doc="test", children=[option_7])
|
||||
|
|
Loading…
Reference in a new issue