support optional to condition to *list

This commit is contained in:
Emmanuel Garette 2021-02-15 18:23:57 +01:00
parent 5821b62f39
commit 86ec629ce3
21 changed files with 94 additions and 20 deletions

View file

@ -43,3 +43,7 @@ FIXME expliquer les noms des variables dans les extras
## Les templates ## Les templates
- Type creole - Type creole
FIXME :
- une variable avec nom unique sauf pour extra

View file

@ -1,13 +0,0 @@
FIXME
<!ATTLIST variable remove_condition (True|False) "False">
<!ELEMENT condition ((target | param)+ )>
<!ATTLIST condition name (disabled_if_in|disabled_if_not_in|hidden_if_in|hidden_if_not_in|mandatory_if_in|mandatory_if_not_in) #REQUIRED>
<!ATTLIST condition source CDATA #REQUIRED>
<!ATTLIST condition fallback (True|False) "False">
<!ATTLIST condition force_condition_on_fallback (True|False) "False">
<!ATTLIST condition force_inverse_condition_on_fallback (True|False) "False">
on peut mettre plusieurs param (oui ou maybe)

View file

@ -1,4 +1,4 @@
# Cible de la fonction de type "variable" # Cible de type "variable"
Par défaut une cible est de type variable. Par défaut une cible est de type variable.

View file

@ -190,6 +190,9 @@ class ConditionAnnotator(TargetAnnotator, ParamAnnotator, Walk):
listvars, listvars,
fills, fills,
) )
elif not target.optional:
msg = f'cannot found target "{target.type}" "{target.name}"'
raise DictConsistencyError(_(msg), 2, target.xmlfiles)
remove_targets.append(target_idx) remove_targets.append(target_idx)
remove_targets.sort(reverse=True) remove_targets.sort(reverse=True)
for target_idx in remove_targets: for target_idx in remove_targets:

View file

@ -74,7 +74,7 @@ class TargetAnnotator:
raise err raise err
# for optional variable # for optional variable
if not target.optional: if not target.optional:
msg = f'cannot found target "{target.name}"' msg = f'cannot found target "{target.type}" "{target.name}"'
raise DictConsistencyError(_(msg), 12, target.xmlfiles) from err raise DictConsistencyError(_(msg), 12, target.xmlfiles) from err
remove_targets.append(index) remove_targets.append(index)
remove_targets.sort(reverse=True) remove_targets.sort(reverse=True)

View file

@ -19,7 +19,6 @@
<param>oui</param> <param>oui</param>
<target type="variable">mode_conteneur_actif</target> <target type="variable">mode_conteneur_actif</target>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>
<target type="filelist">afilllist</target>
</condition> </condition>
</constraints> </constraints>
</rougail> </rougail>

View file

@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<variables>
<variable name="condition" type="boolean"/>
</variables>
<constraints>
<condition name="disabled_if_in" source="condition">
<param>True</param>
<target type="filelist" optional="True">unknown</target>
</condition>
</constraints>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

View file

@ -0,0 +1 @@
{"rougail.condition": true}

View file

@ -0,0 +1,16 @@
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 *
option_2 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -19,7 +19,6 @@
<param type="nil"/> <param type="nil"/>
<target type="variable">mode_conteneur_actif</target> <target type="variable">mode_conteneur_actif</target>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>
<target type="filelist">afilllist</target>
</condition> </condition>
</constraints> </constraints>
</rougail> </rougail>

View file

@ -19,7 +19,6 @@
<param>oui</param> <param>oui</param>
<target type="variable">mode_conteneur_actif</target> <target type="variable">mode_conteneur_actif</target>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>
<target type="filelist">afilllist</target>
</condition> </condition>
<condition name="disabled_if_in" source="activer_client_ldap" fallback="True"> <condition name="disabled_if_in" source="activer_client_ldap" fallback="True">
<param>non</param> <param>non</param>

View file

@ -19,7 +19,6 @@
<param>oui</param> <param>oui</param>
<target type="variable">mode_conteneur_actif</target> <target type="variable">mode_conteneur_actif</target>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>
<target type="filelist">afilllist</target>
</condition> </condition>
<condition name="disabled_if_in" source="activer_client_ldap" fallback="True" force_condition_on_fallback="True"> <condition name="disabled_if_in" source="activer_client_ldap" fallback="True" force_condition_on_fallback="True">
<param>non</param> <param>non</param>

View file

@ -19,7 +19,6 @@
<param>oui</param> <param>oui</param>
<target>mode_conteneur_actif</target> <target>mode_conteneur_actif</target>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>
<target type="filelist">afilllist</target>
</condition> </condition>
</constraints> </constraints>
</rougail> </rougail>

View file

@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<variables>
<variable name="condition" type="boolean"/>
<family name="general">
<variable name="my_variable"/>
</family>
</variables>
<constraints>
<condition name="disabled_if_in" source="condition">
<param>True</param>
<target type="family" optional="True">general</target>
<target type="family" optional="True">general2</target>
</condition>
</constraints>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

View file

@ -0,0 +1 @@
{"rougail.condition": true}

View file

@ -0,0 +1,18 @@
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 *
option_2 = BoolOption(name="condition", doc="condition", default=True, properties=frozenset({"mandatory", "normal"}))
option_4 = StrOption(name="my_variable", doc="my_variable", properties=frozenset({"normal"}))
option_3 = OptionDescription(name="general", doc="general", children=[option_4], properties=frozenset({"normal", Calculation(func.calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_2, todict=True), 'expected': ParamValue(True)}))}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<variables>
<variable name="condition" type="boolean"/>
</variables>
<constraints>
<condition name="disabled_if_in" source="condition">
<param>True</param>
<target type="filelist">unknown</target>
</condition>
</constraints>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->