add multiple disable_if_in support
This commit is contained in:
parent
e618b3b42c
commit
1dcdbd474d
|
@ -220,22 +220,19 @@ class ConditionAnnotator:
|
|||
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
|
||||
or_needed = True
|
||||
for param in fill.param:
|
||||
if hasattr(param, 'name') and param.name == 'condition_operator':
|
||||
or_needed = False
|
||||
break
|
||||
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)
|
||||
fill.index = -1
|
||||
if not hasattr(self.objectspace.space.constraints, 'fill'):
|
||||
self.objectspace.space.constraints.fill = []
|
||||
self.objectspace.space.constraints.fill.append(fill)
|
||||
|
@ -248,15 +245,23 @@ class ConditionAnnotator:
|
|||
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)
|
||||
or_needed = len(condition.param) != 1
|
||||
for param in condition.param:
|
||||
fill.index += 1
|
||||
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(param, 'text', None)
|
||||
fill.param.append(param4)
|
||||
if or_needed:
|
||||
param5 = self.objectspace.param(target.xmlfiles)
|
||||
param5.name = 'condition_operator'
|
||||
param5.text = 'OR'
|
||||
fill.param.append(param5)
|
||||
remove_targets.append(target_idx)
|
||||
remove_targets.sort(reverse=True)
|
||||
for target_idx in remove_targets:
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<services>
|
||||
<service name="test">
|
||||
<file name="/tmp/file1" filelist="afilllist"/>
|
||||
</service>
|
||||
</services>
|
||||
<variables>
|
||||
<family name="general">
|
||||
<variable name="condition" type="string" description="No change">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
<variable name="mode_conteneur_actif2" type="string" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
</family>
|
||||
</variables>
|
||||
|
||||
<constraints>
|
||||
<condition name="disabled_if_in" source="condition">
|
||||
<param>oui</param>
|
||||
<param>maybe</param>
|
||||
<target type="variable">mode_conteneur_actif</target>
|
||||
<target type="variable">mode_conteneur_actif2</target>
|
||||
<target type="filelist">afilllist</target>
|
||||
</condition>
|
||||
</constraints>
|
||||
</rougail>
|
||||
<!-- vim: ts=4 sw=4 expandtab
|
||||
-->
|
|
@ -0,0 +1 @@
|
|||
{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "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": true}
|
|
@ -0,0 +1,32 @@
|
|||
from importlib.machinery import SourceFileLoader
|
||||
from importlib.util import spec_from_loader, module_from_spec
|
||||
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||
spec = spec_from_loader(loader.name, loader)
|
||||
func = module_from_spec(spec)
|
||||
loader.exec_module(func)
|
||||
for key, value in dict(locals()).items():
|
||||
if key != ['SourceFileLoader', 'func']:
|
||||
setattr(func, key, value)
|
||||
try:
|
||||
from tiramisu3 import *
|
||||
except:
|
||||
from tiramisu import *
|
||||
from rougail.tiramisu import ConvertDynOptionDescription
|
||||
option_3 = StrOption(name="condition", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
|
||||
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))}))
|
||||
option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))}))
|
||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"}))
|
||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||
option_10 = StrOption(name="group", doc="group", default="root")
|
||||
option_11 = StrOption(name="mode", doc="mode", default="0644")
|
||||
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=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")})))
|
||||
option_9 = OptionDescription(name="file1", doc="file1", 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])
|
||||
option_7.impl_set_information('manage', True)
|
||||
option_6 = OptionDescription(name="services", doc="services", children=[option_7], properties=frozenset({"hidden"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_6])
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<services>
|
||||
<service name="test">
|
||||
<file name="/tmp/file1" filelist="afilllist"/>
|
||||
</service>
|
||||
</services>
|
||||
<variables>
|
||||
<family name="general">
|
||||
<variable name="condition" type="string" description="No change">
|
||||
<value>oui</value>
|
||||
</variable>
|
||||
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
<variable name="mode_conteneur_actif2" type="string" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
</family>
|
||||
</variables>
|
||||
|
||||
<constraints>
|
||||
<condition name="disabled_if_in" source="condition">
|
||||
<param>oui</param>
|
||||
<param>maybe</param>
|
||||
<target type="variable">mode_conteneur_actif</target>
|
||||
<target type="variable">mode_conteneur_actif2</target>
|
||||
<target type="filelist">afilllist</target>
|
||||
</condition>
|
||||
</constraints>
|
||||
</rougail>
|
||||
<!-- vim: ts=4 sw=4 expandtab
|
||||
-->
|
|
@ -0,0 +1 @@
|
|||
{"rougail.general.condition": "oui", "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}
|
|
@ -0,0 +1,32 @@
|
|||
from importlib.machinery import SourceFileLoader
|
||||
from importlib.util import spec_from_loader, module_from_spec
|
||||
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py')
|
||||
spec = spec_from_loader(loader.name, loader)
|
||||
func = module_from_spec(spec)
|
||||
loader.exec_module(func)
|
||||
for key, value in dict(locals()).items():
|
||||
if key != ['SourceFileLoader', 'func']:
|
||||
setattr(func, key, value)
|
||||
try:
|
||||
from tiramisu3 import *
|
||||
except:
|
||||
from tiramisu import *
|
||||
from rougail.tiramisu import ConvertDynOptionDescription
|
||||
option_3 = StrOption(name="condition", doc="No change", default="oui", properties=frozenset({"mandatory", "normal"}))
|
||||
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))}))
|
||||
option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))}))
|
||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"}))
|
||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||
option_10 = StrOption(name="group", doc="group", default="root")
|
||||
option_11 = StrOption(name="mode", doc="mode", default="0644")
|
||||
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=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")})))
|
||||
option_9 = OptionDescription(name="file1", doc="file1", 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])
|
||||
option_7.impl_set_information('manage', True)
|
||||
option_6 = OptionDescription(name="services", doc="services", children=[option_7], properties=frozenset({"hidden"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_6])
|
|
@ -15,7 +15,7 @@
|
|||
</variables>
|
||||
|
||||
<constraints>
|
||||
<condition name="disabled_if_not_in" source="condition" force_inverse_condition_on_fallback="True">
|
||||
<condition name="disabled_if_not_in" source="unknown" force_inverse_condition_on_fallback="True" fallback="True">
|
||||
<param>oui</param>
|
||||
<target type="variable">mode_conteneur_actif</target>
|
||||
<target type="variable">mode_conteneur_actif2</target>
|
||||
|
|
|
@ -13,8 +13,8 @@ except:
|
|||
from tiramisu import *
|
||||
from rougail.tiramisu import ConvertDynOptionDescription
|
||||
option_3 = StrOption(name="condition", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
|
||||
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))}))
|
||||
option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))}))
|
||||
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"disabled", "mandatory", "normal"}))
|
||||
option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"disabled", "mandatory", "normal"}))
|
||||
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"}))
|
||||
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])
|
||||
|
|
|
@ -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=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5), 'expected_1': ParamValue("oui")})))
|
||||
option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5), 'expected_1': ParamValue("oui"), 'condition_operator': ParamValue("OR")})))
|
||||
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,12 +1,10 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
|
||||
<services>
|
||||
<service name="test">
|
||||
<file name="/tmp/file1" filelist="afilllist"/>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
<variables>
|
||||
<family name="general">
|
||||
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
|
||||
|
@ -17,7 +15,6 @@
|
|||
</variable>
|
||||
</family>
|
||||
</variables>
|
||||
|
||||
<constraints>
|
||||
<condition name="hidden_if_in" source="activer_clam" fallback="True">
|
||||
<param>non</param>
|
||||
|
|
Loading…
Reference in New Issue