Compare commits
3 Commits
5821b62f39
...
0585ab0b11
Author | SHA1 | Date |
---|---|---|
Emmanuel Garette | 0585ab0b11 | |
Emmanuel Garette | 6d571d8cac | |
Emmanuel Garette | 86ec629ce3 |
|
@ -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
|
||||||
|
|
|
@ -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)
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Les conditions
|
||||||
|
|
||||||
|
- [Déclaration d'une condition](condition.md)
|
||||||
|
- [Les différentes conditions](conditions.md)
|
||||||
|
- [Réfinition](redefine.md)
|
|
@ -0,0 +1,50 @@
|
||||||
|
# Les conditions
|
||||||
|
|
||||||
|
Les conditions permettent d'ajouter ou de supprimer des propriétés à une [variable](../variable/README.md), une [famille](../family/README.md), un [fichier](../service/file.md), un [port](../service/port.md) ou une [ip](../service/ip.md) suivant le contexte.
|
||||||
|
|
||||||
|
Nous allons nous concentrer ici sur la condition hidden_if_in, mais [il existe d'autre conditions](conditions.md).
|
||||||
|
|
||||||
|
La condition hidden_if_in permet de cacher une variable où une famille à l'utilisateur, mais cette variable est toujours accessible dans un calcul, un vérification ou dans un template.
|
||||||
|
|
||||||
|
```
|
||||||
|
<variables>
|
||||||
|
<variable name="condition" type="boolean"/>
|
||||||
|
<variable name="my_variable"/>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<condition name="hidden_if_in" source="condition">
|
||||||
|
<param>True</param>
|
||||||
|
<target>my_variable</target>
|
||||||
|
</condition>
|
||||||
|
</constraints>
|
||||||
|
```
|
||||||
|
|
||||||
|
Le [paramètres](../param/README.md) de la condition permet de définir les valeurs que doit avoir la source pour appliquer l'action.
|
||||||
|
|
||||||
|
La [cible](../target/README.md) de la condition est ici "my_variable".
|
||||||
|
|
||||||
|
Donc ici la variable est caché à l'utilisateur si la variable "condition" est à True (le paramètre).
|
||||||
|
|
||||||
|
Il est également possible de mettre plusieurs paramètre :
|
||||||
|
|
||||||
|
```
|
||||||
|
<variables>
|
||||||
|
<variable name="condition"/>
|
||||||
|
<variable name="my_variable"/>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<condition name="hidden_if_in" source="condition">
|
||||||
|
<param>yes</param>
|
||||||
|
<param>maybe</param>
|
||||||
|
<target>my_variable</target>
|
||||||
|
</condition>
|
||||||
|
</constraints>
|
||||||
|
```
|
||||||
|
|
||||||
|
FIXME
|
||||||
|
<!ELEMENT condition ((target|param)+)>
|
||||||
|
<!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">
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Les conditions
|
||||||
|
|
||||||
|
## Les conditions \_if_in et \_if_not_in
|
||||||
|
|
||||||
|
Il existe deux types de conditions :
|
||||||
|
|
||||||
|
- les conditions dont le nom fini par \_if_in : dans ce cas si la variable source est égal à un des paramètres, l'action est effective
|
||||||
|
- les conditions dont le nom fini par \_if_not_in : dans ce cas si la variable source est différents de tous les paramètres, l'action est effective
|
||||||
|
|
||||||
|
## Désactivation
|
||||||
|
|
||||||
|
Il est possible de désactiver une [variable](../variable/README.md) ou une [famille](../family/README.md) avec les conditions :
|
||||||
|
|
||||||
|
- disabled_if_in
|
||||||
|
- disabled_if_not_in
|
||||||
|
|
||||||
|
## Caché
|
||||||
|
|
||||||
|
Il est possible de cacher une [variable](../variable/README.md), une [famille](../family/README.md), un [fichier](../service/file.md), un [port](../service/port.md) ou une [ip](../service/ip.md) avec les conditions :
|
||||||
|
|
||||||
|
- hidden_if_in
|
||||||
|
- hidden_if_not_in
|
||||||
|
|
||||||
|
## Obligatoire
|
||||||
|
|
||||||
|
Il est possible de rendre obligatoire une [variable](../variable/README.md) avec les conditions :
|
||||||
|
|
||||||
|
- mandatory_if_in
|
||||||
|
- mandatory_if_not_in
|
|
@ -0,0 +1,29 @@
|
||||||
|
# Rédéfinition
|
||||||
|
|
||||||
|
Il se peut que dans un dictionnaire on décide de définir une condition.
|
||||||
|
|
||||||
|
Dans un second dictionnaire il est possible de supprimer cette condition.
|
||||||
|
|
||||||
|
Dans un premier dictionnaire déclarons notre variable et notre calcule :
|
||||||
|
|
||||||
|
```
|
||||||
|
<variables>
|
||||||
|
<variable name="condition" type="boolean"/>
|
||||||
|
<variable name="my_variable"/>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<condition name="hidden_if_in" source="condition">
|
||||||
|
<param>True</param>
|
||||||
|
<target>my_variable</target>
|
||||||
|
</condition>
|
||||||
|
</constraints>
|
||||||
|
```
|
||||||
|
|
||||||
|
Dans un second dictionnaire supprimer ce calcul :
|
||||||
|
|
||||||
|
```
|
||||||
|
<variables>
|
||||||
|
<variable name="condition" redefine="True" remove_condition="True"/>
|
||||||
|
</variables>
|
||||||
|
```
|
|
@ -0,0 +1,5 @@
|
||||||
|
# La cible
|
||||||
|
|
||||||
|
- [De type variable)](../target/variable.md)
|
||||||
|
- [De type famille)](../target/family.md)
|
||||||
|
- [De type \*list](../target/list.md)
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Cible de type "variable"
|
||||||
|
|
||||||
|
Une cible peut être de type famille :
|
||||||
|
|
||||||
|
```
|
||||||
|
<target type="family">my_family</target>
|
||||||
|
```
|
||||||
|
|
||||||
|
Mais une target peut être optionnelle. C'est à dire que si la famille n'existe pas, l'action ne sera pas associé à cette famille.
|
||||||
|
|
||||||
|
```
|
||||||
|
<target type="family" optional="True">my_family</target>
|
||||||
|
```
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Cible de type \*list
|
||||||
|
|
||||||
|
## Les différences cible de type \*.list
|
||||||
|
|
||||||
|
### filelist
|
||||||
|
|
||||||
|
Une cible peut être de type [fichier](../service/file.md) :
|
||||||
|
|
||||||
|
```
|
||||||
|
<target type="filelist">example</target>
|
||||||
|
```
|
||||||
|
|
||||||
|
### portlist
|
||||||
|
|
||||||
|
Une cible peut être de type [port](../service/port.md) :
|
||||||
|
|
||||||
|
```
|
||||||
|
<target type="portlist">example</target>
|
||||||
|
```
|
||||||
|
|
||||||
|
### iplist
|
||||||
|
|
||||||
|
Une cible peut être de type [ip](../service/ip.md) :
|
||||||
|
|
||||||
|
```
|
||||||
|
<target type="iplist">example</target>
|
||||||
|
```
|
||||||
|
|
||||||
|
## La cible optionnelle
|
||||||
|
|
||||||
|
Mais une target peut être optionnelle. C'est à dire que si la \*list n'existe pas, l'action ne sera pas associé.
|
||||||
|
|
||||||
|
```
|
||||||
|
<target type="filelist" optional="True">unknown</target>
|
||||||
|
```
|
|
@ -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.
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -62,19 +62,22 @@ class TargetAnnotator:
|
||||||
f'is not allowed')
|
f'is not allowed')
|
||||||
raise DictConsistencyError(msg, 8, obj.xmlfiles)
|
raise DictConsistencyError(msg, 8, obj.xmlfiles)
|
||||||
if target.type == 'family':
|
if target.type == 'family':
|
||||||
|
if obj.name not in ['disabled_if_in', 'disabled_if_not_in', "hidden_if_in", "hidden_if_not_in"]:
|
||||||
|
msg = _(f'target "{target.type}" not allow with "{obj.name}"')
|
||||||
|
raise DictConsistencyError(msg, 51, target.xmlfiles)
|
||||||
target.name = self.objectspace.paths.get_family(target.name,
|
target.name = self.objectspace.paths.get_family(target.name,
|
||||||
obj.namespace,
|
obj.namespace,
|
||||||
)
|
)
|
||||||
elif target.type.endswith('list') and \
|
elif target.type.endswith('list') and \
|
||||||
obj.name not in ['disabled_if_in', 'disabled_if_not_in']:
|
obj.name not in ['disabled_if_in', 'disabled_if_not_in']:
|
||||||
msg = _(f'target "{target.type}" not allow')
|
msg = _(f'target "{target.type}" not allow with "{obj.name}"')
|
||||||
raise DictConsistencyError(msg, 10, target.xmlfiles)
|
raise DictConsistencyError(msg, 10, target.xmlfiles)
|
||||||
except DictConsistencyError as err:
|
except DictConsistencyError as err:
|
||||||
if err.errno != 42:
|
if err.errno != 42:
|
||||||
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)
|
||||||
|
|
|
@ -132,7 +132,7 @@
|
||||||
<!ATTLIST param optional (True|False) "False">
|
<!ATTLIST param optional (True|False) "False">
|
||||||
|
|
||||||
<!ELEMENT target (#PCDATA)>
|
<!ELEMENT target (#PCDATA)>
|
||||||
<!ATTLIST target type (family|variable|filelist|iplist|portlist) "variable">
|
<!ATTLIST target type (variable|family|filelist|iplist|portlist) "variable">
|
||||||
<!ATTLIST target optional (True|False) "False">
|
<!ATTLIST target optional (True|False) "False">
|
||||||
|
|
||||||
<!ELEMENT group (follower+)>
|
<!ELEMENT group (follower+)>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
|
-->
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.condition": true}
|
|
@ -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])
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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
|
||||||
|
-->
|
|
@ -0,0 +1 @@
|
||||||
|
{"rougail.condition": true}
|
|
@ -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])
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
<rougail>
|
||||||
|
<variables>
|
||||||
|
<family name="general">
|
||||||
|
<variable name="condition" type="boolean"/>
|
||||||
|
</family>
|
||||||
|
<family name="general2">
|
||||||
|
<variable name="my_variable"/>
|
||||||
|
</family>
|
||||||
|
</variables>
|
||||||
|
|
||||||
|
<constraints>
|
||||||
|
<condition name="mandatory_if_in" source="condition">
|
||||||
|
<param>oui</param>
|
||||||
|
<target type="family">general2</target>
|
||||||
|
</condition>
|
||||||
|
</constraints>
|
||||||
|
</rougail>
|
||||||
|
<!-- vim: ts=4 sw=4 expandtab
|
||||||
|
-->
|
|
@ -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
|
||||||
|
-->
|
Loading…
Reference in New Issue