Compare commits

..

14 Commits

196 changed files with 1774 additions and 944 deletions

View File

@ -1,5 +1,4 @@
# Les vérifications des valeurs # Les vérifications des valeurs
- [Fonction de vérification](function.md) - [Fonction de vérification](function.md)
- [Les variables à choix](valid_enum.md)
- [Réfinition](redefine.md) - [Réfinition](redefine.md)

View File

@ -1,46 +0,0 @@
# Les variables à choix
Une variable à choix est d'abord une variable avec une [fonction check](function.md).
## Les variables à choix simple
Il est possible d'imposer une liste de valeur pour une variable particulière :
```
<check name="valid_enum">
<param>yes</param>
<param>no</param>
<param>maybe</param>
<target>my_variable</target>
</check>
```
Dans ce cas, seule les valeurs proposés sont possible pour cette variable.
Par défaut, cette variable est obligatoire. Cela signifie qu'il n'est pas possible de spécifier "None" à cette variable.
## Les variables à choix avec valeur None
Il y a deux possibilités pour avoir une valeur "None" dans les choix :
- rendre la variable non obligatoire, cela va ajouter un choix "None" dans la liste :
```
<variable name="my_variable" mandatory="False">
```
Ou en ajoutant le paramètre "None" :
```
<check name="valid_enum">
<param>yes</param>
<param>no</param>
<param type='nil'/>
<param>maybe</param>
<target>my_variable</target>
</check>
```
## La valeur par défaut
Si aucune valeur n'est spécifié pour la variable, automatiquement le premier choix va est placé comme valeur par défaut.

View File

@ -29,6 +29,16 @@ Un service non géré ne peut conteneur que des fichiers.
## Désactiver la génération d'un service ## Désactiver la génération d'un service
Il est possible de désactiver un service. Pour cela il faut rajouter l'attribut "disabled" à True :
```
<services>
<service name="test" disabled="True"/>
</services>
```
Dans ce cas, tous les services et les éléments qu'il compose ([fichier](file.md), ...) seront désactivés.
Il est possible de définir une [condition](../condition/README.md) de type "disabled_if_in" ou "disabled_if_not_in" sur une balise service : Il est possible de définir une [condition](../condition/README.md) de type "disabled_if_in" ou "disabled_if_not_in" sur une balise service :
``` ```

View File

@ -116,7 +116,6 @@ Les variables booléans sont par défaut obligatoire. Pour qu'une variable bool
``` ```
Les variables avec une valeur par défaut (non calculée) sont également automatiquement obligatoire. Les variables avec une valeur par défaut (non calculée) sont également automatiquement obligatoire.
[Les variables à choix](../check/valid_enum.md) sans choix "None" sont également automatiquement obligatoire.
## Valeur par défaut d'une variable ## Valeur par défaut d'une variable

91
doc/variable/choice.md Normal file
View File

@ -0,0 +1,91 @@
# Les variables à choix
## Une variable à choix
Il est possible d'imposer une liste de valeur pour une variable particulière :
```
<variable name="my_variable" type="choice">
<choice>val1</choice>
<choice>val2</choice>
<choice>val3</choice>
</variable>
```
Dans ce cas, seules les valeurs proposées sont possibles pour cette variable.
Cette variable n'est pas obligatoire dont il est possible de mettre la valeur "None".
Si la variable est obligatoire ou si une valeur est précisée (la variable passe obligatoire) alors la valeur "None" n'est plus autorisé :
```
<variable name="my_variable" type="choice">
<choice>val1</choice>
<choice>val2</choice>
<choice>val3</choice>
<value>val1</value>
</variable>
```
## Un variable à choix typée
Par défaut les choix sont de type "string". Il est possible de préciser des nombres, des booléens ou la valeur None :
```
<variable name="my_variable" type="choice">
<choice>val1</choice>
<choice type="string">val2</choice>
<choice type="number">3</choice>
<choice type="boolean">True</choice>
<choice type="nil"/>
</variable>
```
Comme vu précédement ajouter la valeur None n'est pas utile parce qu'elle est automatiquement ajouté si la variable n'est pas obligatoire.
## Ajouter une option à une variable à choix existante
Pour ajouter un choix à une variable à choix existante, rien de plus simple, juste redéfinir la variable en ajoutant le choix voulu :
```
<variable name="my_variable" redefine="True">
<choice>val4</choice>
</variable>
```
## Redéfinir une option à choix
Si on veut supprimer un choix ou redéfinir complètement la liste, il faut redéfinir cette variable et ajouter l'attribut "remove_choice" à "True" :
```
<variable name="my_variable" redefine="True" remove_choice="True">
<choice>val1</choice>
<choice>val2</choice>
</variable>
```
Dans ce cas toutes les anciens choix ne seront plus possible. Seuls les nouveaux le seront.
## Un variable à choix provenant d'une variable
Une variable à valeur multiple peut servir de source des choix :
```
<variable name="my_variable" type="choice">
<choice type="variable">other_variable</choice>
</variable>
```
Dans ce cas, toutes les valeurs de la variable seront des choix utilisables par l'utilisateur.
Seul un choice de type "variable" est possible par variable.
## Un variable à choix provenant d'une fonction
```
<variable name="my_variable" type="choice">
<choice type="function" name="trange">
<param type="number">0</param>
<param type="number">10</param>
</choice>
<value type="number">9</value>
</variable>
```

View File

@ -33,7 +33,7 @@ from rougail.utils import load_modules
from rougail.i18n import _ from rougail.i18n import _
from rougail.error import DictConsistencyError, display_xmlfiles from rougail.error import DictConsistencyError, display_xmlfiles
INTERNAL_FUNCTIONS = ['valid_enum', 'valid_in_network', 'valid_differ', 'valid_entier'] INTERNAL_FUNCTIONS = ['valid_in_network', 'valid_differ', 'valid_entier']
class Annotator(TargetAnnotator, ParamAnnotator): class Annotator(TargetAnnotator, ParamAnnotator):
"""Annotate check """Annotate check
@ -58,21 +58,11 @@ class Annotator(TargetAnnotator, ParamAnnotator):
self.convert_target(self.objectspace.space.constraints.check) self.convert_target(self.objectspace.space.constraints.check)
self.convert_param(self.objectspace.space.constraints.check) self.convert_param(self.objectspace.space.constraints.check)
self.check_check() self.check_check()
self.check_valid_enum()
self.check_change_warning() self.check_change_warning()
self.convert_valid_entier() self.convert_valid_entier()
self.convert_check() self.convert_check()
del objectspace.space.constraints.check del objectspace.space.constraints.check
def valid_type_validation(self,
obj,
) -> None:
variable_type = None
if obj.name == 'valid_enum':
for target in obj.target:
variable_type = target.name.type
return variable_type
def check_check(self): # pylint: disable=R0912 def check_check(self): # pylint: disable=R0912
"""valid and manage <check> """valid and manage <check>
""" """
@ -87,119 +77,6 @@ class Annotator(TargetAnnotator, ParamAnnotator):
for idx in remove_indexes: for idx in remove_indexes:
del self.objectspace.space.constraints.check[idx] del self.objectspace.space.constraints.check[idx]
def check_valid_enum(self):
"""verify valid_enum
"""
remove_indexes = []
for idx, check in enumerate(self.objectspace.space.constraints.check):
if check.name != 'valid_enum':
continue
for target in check.target:
if target.name.path in self.objectspace.valid_enums:
check_xmlfiles = display_xmlfiles(self.objectspace.valid_enums\
[target.name.path]['xmlfiles'])
msg = _(f'valid_enum already set in {check_xmlfiles} '
f'for "{target.name.name}", you may have forget remove_check')
raise DictConsistencyError(msg, 3, check.xmlfiles)
if not hasattr(check, 'param'):
msg = _(f'param is mandatory for a valid_enum of variable "{target.name.name}"')
raise DictConsistencyError(msg, 4, check.xmlfiles)
variable_type = target.name.type
values = self._set_valid_enum(target.name,
check,
)
if values:
if hasattr(target.name, 'value'):
# check value
self.check_valid_enum_value(target.name, values)
else:
# no value, set the first choice as default value
new_value = self.objectspace.value(check.xmlfiles)
new_value.name = values[0]
new_value.type = variable_type
target.name.value = [new_value]
remove_indexes.append(idx)
remove_indexes.sort(reverse=True)
for idx in remove_indexes:
del self.objectspace.space.constraints.check[idx]
def _set_valid_enum(self,
variable,
check,
) -> List[Any]:
# build choice
variable.values = []
variable.ori_type = variable.type
variable.type = 'choice'
has_variable = False
values = []
has_nil = False
is_function = False
for param in check.param:
if has_variable:
msg = _(f'only one "variable" parameter is allowed for valid_enum '
f'of variable "{variable.name}"')
raise DictConsistencyError(msg, 5, param.xmlfiles)
if param.type == 'function':
is_function = True
choice = self.objectspace.choice(variable.xmlfiles)
choice.name = param.text
choice.type = 'function'
choice.param = []
variable.values.append(choice)
continue
if is_function:
variable.values[0].param.append(param)
continue
param_type = variable.ori_type
if param.type == 'variable':
has_variable = True
if param.optional is True:
msg = _(f'optional parameter in valid_enum for variable "{variable.name}" '
f'is not allowed')
raise DictConsistencyError(msg, 14, param.xmlfiles)
if not param.text.multi:
msg = _(f'only multi "variable" parameter is allowed for valid_enum '
f'of variable "{variable.name}"')
raise DictConsistencyError(msg, 6, param.xmlfiles)
param_type = 'variable'
elif param.type == 'nil':
has_nil = True
values.append(param.text)
choice = self.objectspace.choice(variable.xmlfiles)
choice.name = param.text
choice.type = param_type
variable.values.append(choice)
if is_function:
return None
if 'mandatory' not in vars(variable):
variable.mandatory = not has_nil
elif variable.mandatory is False:
choice = self.objectspace.choice(variable.xmlfiles)
choice.name = None
choice.type = 'nil'
variable.values.append(choice)
if has_variable:
return None
self.objectspace.valid_enums[variable.path] = {'type': variable.ori_type,
'values': values,
'xmlfiles': check.xmlfiles,
}
return values
@staticmethod
def check_valid_enum_value(variable,
values,
) -> None:
"""check that values in valid_enum are valid
"""
for value in variable.value:
if value.name not in values:
msg = _(f'value "{value.name}" of variable "{variable.name}" is not in list '
f'of all expected values ({values})')
raise DictConsistencyError(msg, 15, value.xmlfiles)
def check_change_warning(self): def check_change_warning(self):
"""convert level to "warnings_only" """convert level to "warnings_only"
""" """

View File

@ -67,7 +67,7 @@ class Annotator(TargetAnnotator, ParamAnnotator, Walk):
obj, obj,
) -> None: ) -> None:
if obj.source.type == 'choice': if obj.source.type == 'choice':
return obj.source.ori_type return None
return obj.source.type return obj.source.type
def convert_auto_freeze(self): def convert_auto_freeze(self):

View File

@ -120,7 +120,7 @@ class Annotator(Walk):
obj, obj,
) -> None: ) -> None:
modes_level = self.objectspace.rougailconfig['modes_level'] modes_level = self.objectspace.rougailconfig['modes_level']
if hasattr(obj, 'mode') and obj.mode not in modes_level: if self._has_mode(obj) and obj.mode not in modes_level:
msg = _(f'mode "{obj.mode}" for "{obj.name}" is not a valid mode, ' msg = _(f'mode "{obj.mode}" for "{obj.name}" is not a valid mode, '
f'valid modes are {modes_level}') f'valid modes are {modes_level}')
raise DictConsistencyError(msg, 71, obj.xmlfiles) raise DictConsistencyError(msg, 71, obj.xmlfiles)
@ -128,23 +128,29 @@ class Annotator(Walk):
def _set_default_mode(self, def _set_default_mode(self,
family: 'self.objectspace.family', family: 'self.objectspace.family',
) -> None: ) -> None:
if hasattr(family, 'mode') and 'mode' in vars(family): if not hasattr(family, 'variable'):
return
if self._has_mode(family):
family_mode = family.mode family_mode = family.mode
else: else:
family_mode = None family_mode = None
if not hasattr(family, 'variable'): leader = None
return
for variable in family.variable.values(): for variable in family.variable.values():
self.valid_mode(variable) if leader is None and hasattr(family, 'leadership') and family.leadership:
leader = variable
if isinstance(variable, self.objectspace.family): if isinstance(variable, self.objectspace.family):
if not variable.leadership: # set default mode a subfamily
if family_mode and not self._has_mode(variable): if family_mode and not self._has_mode(variable):
self._set_auto_mode(variable, family_mode) self._set_auto_mode(variable, family_mode)
continue
func = self._set_default_mode_leader
else: else:
func = self._set_default_mode_variable # set default mode to a variable
func(variable, family_mode) self.valid_mode(variable)
if leader:
self._set_default_mode_leader(leader, variable)
self._set_default_mode_variable(variable, family_mode)
if leader:
# here because follower can change leader mode
self._set_auto_mode(family, leader.mode)
@staticmethod @staticmethod
def _has_mode(obj) -> bool: def _has_mode(obj) -> bool:
@ -174,25 +180,25 @@ class Annotator(Walk):
obj.mode_auto = True obj.mode_auto = True
def _set_default_mode_leader(self, def _set_default_mode_leader(self,
leadership: 'self.objectspace.family', leader: 'self.objectspace.variable',
family_mode: str, follower: 'self.objectspace.variable',
) -> None: ) -> None:
leader_mode = None
leader = next(iter(leadership.variable.values()))
for follower in leadership.variable.values():
self.valid_mode(follower)
if follower.auto_save is True: if follower.auto_save is True:
msg = _(f'leader/followers "{follower.name}" could not be auto_save') msg = _(f'leader/followers "{follower.name}" could not be auto_save')
raise DictConsistencyError(msg, 29, leadership.xmlfiles) raise DictConsistencyError(msg, 29, follower.xmlfiles)
if follower.auto_freeze is True: if follower.auto_freeze is True:
msg = f'leader/followers "{follower.name}" could not be auto_freeze' msg = f'leader/followers "{follower.name}" could not be auto_freeze'
raise DictConsistencyError(_(msg), 30, leadership.xmlfiles) raise DictConsistencyError(_(msg), 30, follower.xmlfiles)
if leader_mode is not None: if leader == follower:
if hasattr(follower, 'mode'): # it's a leader
if not hasattr(leader, 'mode'):
self._set_auto_mode(leader, self.objectspace.rougailconfig['default_variable_mode'])
return
if self._has_mode(follower):
follower_mode = follower.mode follower_mode = follower.mode
else: else:
follower_mode = self.objectspace.rougailconfig['default_variable_mode'] follower_mode = self.objectspace.rougailconfig['default_variable_mode']
if self.modes[leader_mode] > self.modes[follower_mode]: if self.modes[leader.mode] > self.modes[follower_mode]:
if self._has_mode(follower) and not self._has_mode(leader): if self._has_mode(follower) and not self._has_mode(leader):
# if follower has mode but not the leader # if follower has mode but not the leader
self._set_auto_mode(leader, follower_mode) self._set_auto_mode(leader, follower_mode)
@ -200,20 +206,9 @@ class Annotator(Walk):
# leader's mode is minimum level # leader's mode is minimum level
if self._has_mode(follower): if self._has_mode(follower):
msg = _(f'the follower "{follower.name}" is in "{follower_mode}" mode ' msg = _(f'the follower "{follower.name}" is in "{follower_mode}" mode '
f'but leader have the higher mode "{leader_mode}"') f'but leader have the higher mode "{leader.mode}"')
raise DictConsistencyError(msg, 63, follower.xmlfiles) raise DictConsistencyError(msg, 63, follower.xmlfiles)
self._set_auto_mode(follower, leader_mode) self._set_auto_mode(follower, leader.mode)
self._set_default_mode_variable(follower,
family_mode,
)
if leader_mode is None:
if hasattr(leader, 'mode'):
leader_mode = leader.mode
else:
leader_mode = self.objectspace.rougailconfig['default_variable_mode']
if hasattr(leader, 'mode'):
leader_mode = leader.mode
self._set_auto_mode(leadership, leader_mode)
def _change_family_mode(self, def _change_family_mode(self,
family: 'self.objectspace.family', family: 'self.objectspace.family',
@ -224,42 +219,41 @@ class Annotator(Walk):
family_mode = self.objectspace.rougailconfig['default_family_mode'] family_mode = self.objectspace.rougailconfig['default_family_mode']
min_variable_mode = self.objectspace.rougailconfig['modes_level'][-1] min_variable_mode = self.objectspace.rougailconfig['modes_level'][-1]
# change variable mode, but not if variables are not in a family # change variable mode, but not if variables are not in a family
is_leadership = hasattr(family, 'leadership') and family.leadership
if hasattr(family, 'variable'): if hasattr(family, 'variable'):
for variable in family.variable.values(): for idx, variable in enumerate(family.variable.values()):
if isinstance(variable, self.objectspace.family): if isinstance(variable, self.objectspace.family):
if variable.leadership: if not hasattr(variable, 'mode'):
func = self._change_variable_mode_leader
else:
func = None
else:
func = self._change_variable_mode
if func:
func(variable,
family_mode,
)
elif not hasattr(variable, 'mode'):
variable.mode = self.objectspace.rougailconfig['default_family_mode'] variable.mode = self.objectspace.rougailconfig['default_family_mode']
elif idx == 0 and is_leadership:
variable.mode = None
continue
else:
self._change_variable_mode(variable, family_mode, is_leadership)
if self.modes[min_variable_mode] > self.modes[variable.mode]: if self.modes[min_variable_mode] > self.modes[variable.mode]:
min_variable_mode = variable.mode min_variable_mode = variable.mode
if isinstance(family, self.objectspace.family) and \ if not isinstance(family, self.objectspace.family) or is_leadership:
(not hasattr(family, 'mode') or family.mode != min_variable_mode): # it's Variable, Service, ... and leadership
return
if not hasattr(family, 'mode'):
# set the lower variable mode to family # set the lower variable mode to family
if self._has_mode(family): self._set_auto_mode(family, min_variable_mode)
if family.mode != min_variable_mode:
msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and ' msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and '
f'families inside have the higher modes "{min_variable_mode}"') f'families inside have the higher modes "{min_variable_mode}"')
raise DictConsistencyError(msg, 62, family.xmlfiles) raise DictConsistencyError(msg, 62, family.xmlfiles)
self._set_auto_mode(family, min_variable_mode)
def _change_variable_mode(self, def _change_variable_mode(self,
variable, variable,
family_mode: str, family_mode: str,
is_follower: bool,
) -> None: ) -> None:
if hasattr(variable, 'mode'): if hasattr(variable, 'mode'):
variable_mode = variable.mode variable_mode = variable.mode
else: else:
variable_mode = self.objectspace.rougailconfig['default_variable_mode'] variable_mode = self.objectspace.rougailconfig['default_variable_mode']
# none basic variable in high level family has to be in high level # none basic variable in high level family has to be in high level
if self.modes[variable_mode] < self.modes[family_mode]: if not is_follower and self.modes[variable_mode] < self.modes[family_mode]:
if self._has_mode(variable): if self._has_mode(variable):
msg = _(f'the variable "{variable.name}" is in "{variable_mode}" mode ' msg = _(f'the variable "{variable.name}" is in "{variable_mode}" mode '
f'but family has the higher family mode "{family_mode}"') f'but family has the higher family mode "{family_mode}"')
@ -268,18 +262,6 @@ class Annotator(Walk):
if not hasattr(variable, 'mode'): if not hasattr(variable, 'mode'):
variable.mode = variable_mode variable.mode = variable_mode
def _change_variable_mode_leader(self,
leadership,
family_mode: str,
) -> None:
for idx, follower in enumerate(leadership.variable.values()):
if idx == 0:
leader = follower
self._change_variable_mode(follower,
family_mode,
)
leader.mode = None
def dynamic_families(self): def dynamic_families(self):
"""link dynamic families to object """link dynamic families to object
""" """
@ -293,7 +275,7 @@ class Annotator(Walk):
f'to multi variable') f'to multi variable')
raise DictConsistencyError(msg, 16, family.xmlfiles) raise DictConsistencyError(msg, 16, family.xmlfiles)
for variable in family.variable.values(): for variable in family.variable.values():
if isinstance(variable, self.objectspace.family): if isinstance(variable, self.objectspace.family) and not variable.leadership:
msg = _(f'dynamic family "{family.name}" cannot contains another family') msg = _(f'dynamic family "{family.name}" cannot contains another family')
raise DictConsistencyError(msg, 22, family.xmlfiles) raise DictConsistencyError(msg, 22, family.xmlfiles)

View File

@ -47,7 +47,7 @@ class Annotator(Walk):
"""convert groups """convert groups
""" """
# store old leaders family name # store old leaders family name
for family in self.get_families(with_leadership=True): for family in self.get_families():
if not isinstance(family, self.objectspace.family): if not isinstance(family, self.objectspace.family):
continue continue
if not family.leadership: if not family.leadership:
@ -55,7 +55,6 @@ class Annotator(Walk):
if hasattr(family, 'dynamic'): if hasattr(family, 'dynamic'):
msg = _(f'the family "{family.name}" cannot be leadership and dynamic together') msg = _(f'the family "{family.name}" cannot be leadership and dynamic together')
raise DictConsistencyError(msg, 31, family.xmlfiles) raise DictConsistencyError(msg, 31, family.xmlfiles)
family.doc = family.description
for idx, variable in enumerate(family.variable.values()): for idx, variable in enumerate(family.variable.values()):
if idx == 0: if idx == 0:
# it's a leader # it's a leader
@ -72,3 +71,7 @@ class Annotator(Walk):
if family.hidden: if family.hidden:
variable.frozen = True variable.frozen = True
variable.force_default_on_freeze = True variable.force_default_on_freeze = True
if variable.multi is True:
variable.multi = 'submulti'
else:
variable.multi = True

View File

@ -132,6 +132,7 @@ class ParamAnnotator:
msg = _(f'parameter has incompatible type "{param.type}" ' msg = _(f'parameter has incompatible type "{param.type}" '
f'with type "{variable_type}"') f'with type "{variable_type}"')
raise DictConsistencyError(msg, 7, param.xmlfiles) raise DictConsistencyError(msg, 7, param.xmlfiles)
if variable_type != 'choice':
try: try:
option = CONVERT_OPTION[variable_type] option = CONVERT_OPTION[variable_type]
param.text = option.get('func', str)(param.text) param.text = option.get('func', str)(param.text)

View File

@ -106,8 +106,5 @@ class Annotator(Walk):
def convert_variable(self) -> None: def convert_variable(self) -> None:
"""convert variables """convert variables
""" """
for variable in self.get_variables(with_leadership=True): for variable in self.get_variables():
if isinstance(variable, self.objectspace.family):
for follower in variable.variable.values():
self.convert_property(follower)
self.convert_property(variable) self.convert_property(variable)

View File

@ -28,15 +28,13 @@ from os.path import basename
from typing import Tuple from typing import Tuple
from rougail.i18n import _ from rougail.i18n import _
from rougail.utils import normalize_family from rougail.utils import normalize_family, valid_variable_family_name
from rougail.error import DictConsistencyError from rougail.error import DictConsistencyError
# a object's attribute has some annotations # a object's attribute has some annotations
# that shall not be present in the exported (flatened) XML # that shall not be present in the exported (flatened) XML
ERASED_ATTRIBUTES = ('redefine', 'exists', 'optional', 'remove_check', 'namespace', ERASED_ATTRIBUTES = ('redefine', 'namespace', 'xmlfiles', 'disabled', 'name', 'manage')
'remove_condition', 'path', 'instance_mode', 'index', ERASED_ATTRIBUTES2 = ('redefine', 'namespace', 'xmlfiles')
'level', 'remove_fill', 'xmlfiles', 'type', 'reflector_name', ALLOW_ATTRIBUT_NOT_MANAGE = ['file', 'engine', 'target']
'reflector_object',)
ALLOW_ATTRIBUT_NOT_MANAGE = ['file']
class Annotator: class Annotator:
@ -72,14 +70,16 @@ class Annotator:
self.objectspace.space.services.doc = 'services' self.objectspace.space.services.doc = 'services'
self.objectspace.space.services.path = 'services' self.objectspace.space.services.path = 'services'
for service_name, service in self.objectspace.space.services.service.items(): for service_name, service in self.objectspace.space.services.service.items():
valid_variable_family_name(service_name, service.xmlfiles)
activate_obj = self._generate_element('boolean', activate_obj = self._generate_element('boolean',
None, None,
None, None,
'activate', 'activate',
True, not service.disabled,
service, service,
'.'.join(['services', normalize_family(service_name), 'activate']), '.'.join(['services', normalize_family(service_name), 'activate']),
) )
service.disabled = None
for elttype, values in dict(vars(service)).items(): for elttype, values in dict(vars(service)).items():
if elttype == 'servicelist': if elttype == 'servicelist':
self.objectspace.list_conditions.setdefault('servicelist', self.objectspace.list_conditions.setdefault('servicelist',
@ -87,11 +87,12 @@ class Annotator:
values, values,
[]).append(activate_obj) []).append(activate_obj)
continue continue
if not isinstance(values, (dict, list)) or elttype in ERASED_ATTRIBUTES: if elttype in ERASED_ATTRIBUTES:
continue continue
if not service.manage and elttype not in ALLOW_ATTRIBUT_NOT_MANAGE: if not service.manage and elttype not in ALLOW_ATTRIBUT_NOT_MANAGE:
msg = _(f'unmanage service cannot have "{elttype}"') msg = _(f'unmanage service cannot have "{elttype}"')
raise DictConsistencyError(msg, 66, service.xmlfiles) raise DictConsistencyError(msg, 66, service.xmlfiles)
if isinstance(values, (dict, list)):
if elttype != 'ip': if elttype != 'ip':
eltname = elttype + 's' eltname = elttype + 's'
else: else:
@ -110,6 +111,10 @@ class Annotator:
path, path,
) )
setattr(service, elttype, family) setattr(service, elttype, family)
else:
if not hasattr(service, 'information'):
service.information = self.objectspace.information(service.xmlfiles)
setattr(service.information, elttype, values)
manage = self._generate_element('boolean', manage = self._generate_element('boolean',
None, None,
None, None,
@ -156,7 +161,7 @@ class Annotator:
'.'.join([subpath, 'activate']), '.'.join([subpath, 'activate']),
) )
for key in dir(elt): for key in dir(elt):
if key.startswith('_') or key.endswith('_type') or key in ERASED_ATTRIBUTES: if key.startswith('_') or key.endswith('_type') or key in ERASED_ATTRIBUTES2:
continue continue
value = getattr(elt, key) value = getattr(elt, key)
if key == listname: if key == listname:

View File

@ -41,24 +41,16 @@ class Annotator(Walk): # pylint: disable=R0903
return return
self.objectspace = objectspace self.objectspace = objectspace
self.convert_value() self.convert_value()
self.add_choice_nil()
def convert_value(self) -> None: def convert_value(self) -> None:
"""convert value """convert value
""" """
for variable in self.get_variables(with_leadership=True): for variable in self.get_variables():
if isinstance(variable, self.objectspace.family):
variable_type = 'leader'
for follower in variable.variable.values():
self._convert_value(follower,
variable_type,
)
variable_type = 'follower'
else:
self._convert_value(variable) self._convert_value(variable)
def _convert_value(self, def _convert_value(self,
variable, variable,
variable_type: str=None,
) -> None: ) -> None:
# a boolean must have value, the default value is "True" # a boolean must have value, the default value is "True"
if not hasattr(variable, 'value') and variable.type == 'boolean': if not hasattr(variable, 'value') and variable.type == 'boolean':
@ -83,17 +75,31 @@ class Annotator(Walk): # pylint: disable=R0903
if variable.value[0].type == 'calculation': if variable.value[0].type == 'calculation':
variable.default = variable.value[0] variable.default = variable.value[0]
elif variable.multi: elif variable.multi:
if variable_type != 'follower': if not self.objectspace.paths.is_follower(variable.path):
variable.default = [value.name for value in variable.value] variable.default = [value.name for value in variable.value]
if variable_type != 'leader': if not self.objectspace.paths.is_leader(variable.path):
if variable.multi == 'submulti': if variable.multi == 'submulti':
variable.default_multi = [value.name for value in variable.value] variable.default_multi = [value.name for value in variable.value]
else: else:
variable.default_multi = variable.value[0].name variable.default_multi = variable.value[0].name
else: else:
if len(variable.value) > 1: if len(variable.value) > 1:
msg = _(f'the non multi variable "{variable.name}" cannot have ' msg = _(f'the none multi variable "{variable.name}" cannot have '
'more than one value') 'more than one value')
raise DictConsistencyError(msg, 68, variable.xmlfiles) raise DictConsistencyError(msg, 68, variable.xmlfiles)
variable.default = variable.value[0].name variable.default = variable.value[0].name
del variable.value del variable.value
def add_choice_nil(self) -> None:
for variable in self.get_variables():
if variable.type != 'choice':
continue
is_none = False
for choice in variable.choice:
if choice.type == 'nil':
is_none = True
if not variable.mandatory and not is_none:
choice = self.objectspace.choice(variable.xmlfiles)
choice.name = None
choice.type = 'nil'
variable.choice.append(choice)

View File

@ -62,55 +62,43 @@ CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
} }
FORCE_CHOICE = {'schedule': ['none', 'daily', 'weekly', 'monthly'],
'schedulemod': ['pre', 'post'],
}
class Walk: class Walk:
"""Walk to objectspace to find variable or family """Walk to objectspace to find variable or family
""" """
objectspace = None objectspace = None
def get_variables(self, def get_variables(self):
with_leadership: bool=False,
):
"""Iter all variables from the objectspace """Iter all variables from the objectspace
""" """
for family in self.objectspace.space.variables.values(): for family in self.objectspace.space.variables.values():
yield from self._get_variables(family, with_leadership) yield from self._get_variables(family)
def _get_variables(self, def _get_variables(self,
family: 'self.objectspace.family', family: 'self.objectspace.family',
with_leadership: bool
): ):
if hasattr(family, 'variable'): if not hasattr(family, 'variable'):
return
for variable in family.variable.values(): for variable in family.variable.values():
if isinstance(variable, self.objectspace.family): if isinstance(variable, self.objectspace.family):
if variable.leadership is False: yield from self._get_variables(variable)
yield from self._get_variables(variable, with_leadership) else:
continue
if not with_leadership:
for follower in variable.variable.values():
yield follower
continue
yield variable yield variable
def get_families(self, with_leadership=False): def get_families(self):
"""Iter all families from the objectspace """Iter all families from the objectspace
""" """
for family in self.objectspace.space.variables.values(): for family in self.objectspace.space.variables.values():
yield from self._get_families(family, with_leadership) yield from self._get_families(family)
def _get_families(self, def _get_families(self,
family: 'self.objectspace.family', family: 'self.objectspace.family',
with_leadership: bool,
): ):
yield family yield family
if hasattr(family, 'variable'): if not hasattr(family, 'variable'):
return
for fam in family.variable.values(): for fam in family.variable.values():
if isinstance(fam, self.objectspace.family) and (with_leadership or not fam.leadership): if isinstance(fam, self.objectspace.family):
yield from self._get_families(fam, with_leadership) yield from self._get_families(fam)
class Annotator(Walk): # pylint: disable=R0903 class Annotator(Walk): # pylint: disable=R0903
@ -134,23 +122,11 @@ class Annotator(Walk): # pylint: disable=R0903
def convert_variable(self): def convert_variable(self):
"""convert variable """convert variable
""" """
for variable in self.get_variables(with_leadership=True): for variable in self.get_variables():
if isinstance(variable, self.objectspace.family): self._convert_variable(variable)
# first variable is a leader, others are follower
variable_type = 'leader'
for follower in variable.variable.values():
self._convert_variable(follower,
variable_type,
)
variable_type = 'follower'
else:
self._convert_variable(variable,
'variable',
)
def _convert_variable(self, def _convert_variable(self,
variable, variable,
variable_type: str,
) -> None: ) -> None:
if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \ if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \
variable.name in self.forbidden_name: variable.name in self.forbidden_name:
@ -173,61 +149,67 @@ class Annotator(Walk): # pylint: disable=R0903
del variable.value[idx] del variable.value[idx]
if not variable.value: if not variable.value:
del variable.value del variable.value
if hasattr(variable, 'choice'):
if variable.type != 'choice':
msg = _(f'choice for the variable "{variable.name}" not allowed with "{variable.type}" type')
raise DictConsistencyError(msg, 3, variable.xmlfiles)
values = []
choice_type = None
for choice in variable.choice:
if choice_type == 'variable':
msg = _(f'only one "variable" choice is allowed '
f'the variable "{variable.name}"')
raise DictConsistencyError(msg, 5, choice.xmlfiles)
if choice.type == 'nil':
choice.name = None
elif choice.type == 'variable':
choice.name = self.objectspace.paths.get_variable(choice.name)
if not choice.name.multi:
msg = _(f'only multi "variable" is allowed for a choice '
f'of variable "{variable.name}"')
raise DictConsistencyError(msg, 6, choice.xmlfiles)
else:
if not hasattr(choice, 'name'):
msg = _(f'choice for variable "{variable.name}" must have a value')
raise DictConsistencyError(msg, 14, choice.xmlfiles)
choice.name = CONVERT_OPTION.get(choice.type, {}).get('func', str)(choice.name)
if choice_type is None:
choice_type = choice.type
values.append(choice.name)
if choice_type not in ['function', 'variable'] and hasattr(variable, 'value'):
for value in variable.value:
if value.name not in values:
msg = _(f'value "{value.name}" of variable "{variable.name}" is not in list '
f'of all expected values ({values})')
raise DictConsistencyError(msg, 15, value.xmlfiles)
ref_choice = variable.choice[0]
self.objectspace.valid_enums[variable.path] = {'type': ref_choice.type,
'values': values,
'xmlfiles': ref_choice.xmlfiles,
}
elif variable.type == 'choice':
msg = _(f'choice is mandatory for the variable "{variable.name}" with choice type')
raise DictConsistencyError(msg, 4, variable.xmlfiles)
variable.doc = variable.description variable.doc = variable.description
del variable.description del variable.description
if variable_type == 'follower':
if variable.multi is True:
variable.multi = 'submulti'
else:
variable.multi = True
self._convert_valid_enum(variable)
def _convert_valid_enum(self,
variable,
):
"""some types are, in fact, choices
convert this kind of variables into choice
"""
if variable.type in FORCE_CHOICE:
if not hasattr(self.objectspace.space, 'constraints'):
xmlfiles = variable.xmlfiles
self.objectspace.space.constraints = self.objectspace.constraints(xmlfiles)
self.objectspace.space.constraints.namespace = variable.namespace
if not hasattr(self.objectspace.space.constraints, 'check'):
self.objectspace.space.constraints.check = []
check = self.objectspace.check(variable.xmlfiles)
check.name = 'valid_enum'
target = self.objectspace.target(variable.xmlfiles)
target.name = variable.path
check.target = [target]
check.namespace = variable.namespace
check.param = []
for value in FORCE_CHOICE[variable.type]:
param = self.objectspace.param(variable.xmlfiles)
param.text = value
check.param.append(param)
self.objectspace.space.constraints.check.append(check)
variable.type = 'string'
def convert_test(self): def convert_test(self):
"""Convert variable tests value """Convert variable tests value
""" """
for variable in self.get_variables(): for variable in self.get_variables():
if not hasattr(variable, 'test'): if not hasattr(variable, 'test') or not variable.test:
# with we want remove test, we set "" has test value
continue continue
if variable.test:
if not hasattr(variable, 'information'):
variable.information = self.objectspace.information(variable.xmlfiles)
values = variable.test.split('|')
new_values = [] new_values = []
for value in values: for value in variable.test.split('|'):
if value == '': if value == '':
value = None value = None
else: else:
value = CONVERT_OPTION.get(variable.type, {}).get('func', str)(value) value = CONVERT_OPTION.get(variable.type, {}).get('func', str)(value)
new_values.append(value) new_values.append(value)
if not hasattr(variable, 'information'):
variable.information = self.objectspace.information(variable.xmlfiles)
variable.information.test = tuple(new_values) variable.information.test = tuple(new_values)
del variable.test
def convert_help(self): def convert_help(self):
"""Convert variable help """Convert variable help

View File

@ -50,6 +50,10 @@
<!ATTLIST service name CDATA #REQUIRED> <!ATTLIST service name CDATA #REQUIRED>
<!ATTLIST service manage (True|False) "True"> <!ATTLIST service manage (True|False) "True">
<!ATTLIST service servicelist CDATA #IMPLIED> <!ATTLIST service servicelist CDATA #IMPLIED>
<!ATTLIST service disabled (True|False) "False">
<!ATTLIST service engine (none|creole|jinja2) #IMPLIED>
<!ATTLIST service target CDATA #IMPLIED>
<!ATTLIST service type (service|mount) "service">
<!ELEMENT ip (#PCDATA)> <!ELEMENT ip (#PCDATA)>
<!ATTLIST ip iplist CDATA #IMPLIED> <!ATTLIST ip iplist CDATA #IMPLIED>
@ -86,9 +90,9 @@
<!ATTLIST family leadership (True|False) "False"> <!ATTLIST family leadership (True|False) "False">
<!ATTLIST family provider CDATA #IMPLIED> <!ATTLIST family provider CDATA #IMPLIED>
<!ELEMENT variable (value*)> <!ELEMENT variable ((choice*|value*)*)>
<!ATTLIST variable name CDATA #REQUIRED> <!ATTLIST variable name CDATA #REQUIRED>
<!ATTLIST variable type (number|float|string|password|mail|boolean|filename|date|unix_user|ip|local_ip|netmask|network|broadcast|netbios|domainname|hostname|web_address|port|mac|cidr|network_cidr|schedule|schedulemod) "string"> <!ATTLIST variable type (number|float|string|password|mail|boolean|filename|date|unix_user|ip|local_ip|netmask|network|broadcast|netbios|domainname|hostname|web_address|port|mac|cidr|network_cidr|choice) "string">
<!ATTLIST variable description CDATA #IMPLIED> <!ATTLIST variable description CDATA #IMPLIED>
<!ATTLIST variable help CDATA #IMPLIED> <!ATTLIST variable help CDATA #IMPLIED>
<!ATTLIST variable hidden (True|False) "False"> <!ATTLIST variable hidden (True|False) "False">
@ -100,6 +104,7 @@
<!ATTLIST variable auto_freeze (True|False) "False"> <!ATTLIST variable auto_freeze (True|False) "False">
<!ATTLIST variable auto_save (True|False) "False"> <!ATTLIST variable auto_save (True|False) "False">
<!ATTLIST variable mode CDATA #IMPLIED> <!ATTLIST variable mode CDATA #IMPLIED>
<!ATTLIST variable remove_choice (True|False) "False">
<!ATTLIST variable remove_check (True|False) "False"> <!ATTLIST variable remove_check (True|False) "False">
<!ATTLIST variable remove_condition (True|False) "False"> <!ATTLIST variable remove_condition (True|False) "False">
<!ATTLIST variable remove_fill (True|False) "False"> <!ATTLIST variable remove_fill (True|False) "False">
@ -107,6 +112,11 @@
<!ATTLIST variable test CDATA #IMPLIED> <!ATTLIST variable test CDATA #IMPLIED>
<!ELEMENT value (#PCDATA)> <!ELEMENT value (#PCDATA)>
<!ATTLIST value type (string|number|nil|boolean) #IMPLIED>
<!ELEMENT choice (#PCDATA | param)*>
<!ATTLIST choice type (string|number|nil|boolean|function|variable) "string">
<!ATTLIST choice name CDATA #IMPLIED>
<!ELEMENT constraints ((fill*|check*|condition*)*)> <!ELEMENT constraints ((fill*|check*|condition*)*)>

View File

@ -38,9 +38,9 @@ FORCE_REDEFINABLES = ('family', 'follower', 'service', 'disknod', 'variables')
# RougailObjSpace's elements that shall be forced to the UnRedefinable type # RougailObjSpace's elements that shall be forced to the UnRedefinable type
FORCE_UNREDEFINABLES = ('value',) FORCE_UNREDEFINABLES = ('value',)
# RougailObjSpace's elements that shall not be modify # RougailObjSpace's elements that shall not be modify
UNREDEFINABLE = ('multi', 'type', 'leadership') UNREDEFINABLE = ('multi', 'type',)
# RougailObjSpace's elements that did not created automaticly # RougailObjSpace's elements that did not created automaticly
FORCE_ELEMENTS = ('choice', 'property_', 'information') FORCE_ELEMENTS = ('property_', 'information')
# XML text are convert has name # XML text are convert has name
FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value',) FORCED_TEXT_ELTS_AS_NAME = ('choice', 'property', 'value',)
@ -393,7 +393,7 @@ class RougailObjSpace:
for attr, val in child.attrib.items(): for attr, val in child.attrib.items():
if redefine and attr in UNREDEFINABLE: if redefine and attr in UNREDEFINABLE:
msg = _(f'cannot redefine attribute "{attr}" for variable "{child.attrib["name"]}"' msg = _(f'cannot redefine attribute "{attr}" for variable "{child.attrib["name"]}"'
f' in "{xmlfile}", already defined') f' already defined')
raise DictConsistencyError(msg, 48, variableobj.xmlfiles[:-1]) raise DictConsistencyError(msg, 48, variableobj.xmlfiles[:-1])
if attr in self.booleans_attributs: if attr in self.booleans_attributs:
val = convert_boolean(val) val = convert_boolean(val)
@ -410,6 +410,12 @@ class RougailObjSpace:
"""Rougail object tree manipulations """Rougail object tree manipulations
""" """
if child.tag == 'variable': if child.tag == 'variable':
if child.attrib.get('remove_choice', False):
if variableobj.type != 'choice':
msg = _(f'cannot remove choices for variable "{variableobj.path}"'
f' the variable has type "{variableobj.type}"')
raise DictConsistencyError(msg, 33, variableobj.xmlfiles)
variableobj.choice = []
if child.attrib.get('remove_check', False): if child.attrib.get('remove_check', False):
self.remove_check(variableobj.name) self.remove_check(variableobj.name)
if child.attrib.get('remove_condition', False): if child.attrib.get('remove_condition', False):
@ -424,6 +430,7 @@ class RougailObjSpace:
def remove_check(self, name): def remove_check(self, name):
"""Remove a check with a specified target """Remove a check with a specified target
""" """
if hasattr(self.space.constraints, 'check'):
remove_checks = [] remove_checks = []
for idx, check in enumerate(self.space.constraints.check): # pylint: disable=E1101 for idx, check in enumerate(self.space.constraints.check): # pylint: disable=E1101
for target in check.target: for target in check.target:
@ -488,7 +495,7 @@ class RougailObjSpace:
elif isinstance(variableobj, self.family): # pylint: disable=E1101 elif isinstance(variableobj, self.family): # pylint: disable=E1101
family_name = variableobj.name family_name = variableobj.name
if namespace != self.rougailconfig['variable_namespace']: if namespace != self.rougailconfig['variable_namespace']:
family_name = namespace + '.' + family_name family_name = space.path + '.' + family_name
self.paths.add_family(namespace, self.paths.add_family(namespace,
family_name, family_name,
variableobj, variableobj,

View File

@ -255,6 +255,7 @@ class RougailBaseTemplate:
filevar: Dict, filevar: Dict,
type_: str, type_: str,
service_name: str, service_name: str,
service_type: str,
) -> None: ) -> None:
"""Run templatisation on one file """Run templatisation on one file
""" """
@ -275,10 +276,11 @@ class RougailBaseTemplate:
var = variable[idx] var = variable[idx]
else: else:
var = None var = None
func = f'_instance_{type_}' func = f'get_data_{type_}'
data = getattr(self, func)(filevar, data = getattr(self, func)(filevar,
filename, filename,
service_name, service_name,
service_type,
variable, variable,
idx, idx,
) )
@ -319,10 +321,26 @@ class RougailBaseTemplate:
for included in (True, False): for included in (True, False):
for service_obj in await self.config.option('services').list('all'): for service_obj in await self.config.option('services').list('all'):
service_name = await service_obj.option.name() service_name = await service_obj.option.name()
service_type = await service_obj.information.get('type', 'service')
if await service_obj.option('activate').value.get() is False: if await service_obj.option('activate').value.get() is False:
if included is False: if included is False:
self.desactive_service(service_name) self.desactive_service(service_name, service_type)
continue continue
if not included:
engine = await service_obj.information.get('engine', None)
if engine:
self.instance_file({'engine': engine},
'service',
service_name,
service_type,
)
target_name = await service_obj.information.get('target', None)
if target_name:
self.target_service(service_name,
target_name,
service_type,
engine is None,
)
for fills in await service_obj.list('optiondescription'): for fills in await service_obj.list('optiondescription'):
type_ = await fills.option.name() type_ = await fills.option.name()
for fill_obj in await fills.list('all'): for fill_obj in await fills.list('all'):
@ -335,10 +353,14 @@ class RougailBaseTemplate:
elif included is True: elif included is True:
continue continue
if fill['activate']: if fill['activate']:
self.instance_file(fill, type_, service_name) self.instance_file(fill,
type_,
service_name,
service_type,
)
else: else:
self.log.debug(_("Instantiation of file '{filename}' disabled")) self.log.debug(_("Instantiation of file '{filename}' disabled"))
self.post_instance_service(service_name) self.post_instance_service(service_name, service_type)
self.post_instance() self.post_instance()
chdir(ori_dir) chdir(ori_dir)
@ -356,27 +378,40 @@ class RougailBaseTemplate:
dico[key] = await obj.information.get(key, default_value) dico[key] = await obj.information.get(key, default_value)
def desactive_service(self, def desactive_service(self,
service_name: str, *args,
): ):
raise NotImplementedError(_('cannot desactivate a service')) raise NotImplementedError(_('cannot desactivate a service'))
def post_instance_service(self, service_name): # pragma: no cover def target_service(self,
service_name: str,
*args,
):
raise NotImplementedError(_('cannot use target for the service {service_name}'))
def post_instance_service(self,
*args,
): # pragma: no cover
pass pass
def post_instance(self): # pragma: no cover def post_instance(self): # pragma: no cover
pass pass
def _instance_ip(self, def get_data_ip(self,
*args, *args,
) -> None: # pragma: no cover ) -> None: # pragma: no cover
raise NotImplementedError(_('cannot instanciate this service type ip')) raise NotImplementedError(_('cannot instanciate this service type ip'))
def _instance_files(self, def get_data_files(self,
*args, *args,
) -> None: # pragma: no cover ) -> None: # pragma: no cover
raise NotImplementedError(_('cannot instanciate this service type file')) raise NotImplementedError(_('cannot instanciate this service type file'))
def _instance_overrides(self, def get_data_service(self,
*args,
) -> None: # pragma: no cover
raise NotImplementedError(_('cannot instanciate this service'))
def get_data_overrides(self,
*args, *args,
) -> None: # pragma: no cover ) -> None: # pragma: no cover
raise NotImplementedError(_('cannot instanciate this service type override')) raise NotImplementedError(_('cannot instanciate this service type override'))

View File

@ -38,9 +38,13 @@ IPAddressDeny=any
""" """
ROUGAIL_TMPL_TEMPLATE = """%def display(%%file, %%filename) ROUGAIL_DEST = '/usr/local/lib'
ROUGAIL_GLOBAL_SYSTEMD_FILE = '/usr/lib/systemd/system'
ROUGAIL_TMPL_TEMPLATE = f"""%def display(%%file, %%filename)
%if %%filename.startswith('/etc/') or %%filename.startswith('/var/') or %%filename.startswith('/srv/') %if %%filename.startswith('/etc/') or %%filename.startswith('/var/') or %%filename.startswith('/srv/')
C %%filename %%file.mode %%file.owner %%file.group - /usr/local/lib%%filename C %%filename %%file.mode %%file.owner %%file.group - {ROUGAIL_DEST}%%filename
z %%filename - - - - - z %%filename - - - - -
%end if %end if
%end def %end def
@ -70,10 +74,11 @@ class RougailSystemdTemplate(RougailBaseTemplate):
self.ip_per_service = None self.ip_per_service = None
super().__init__(config, rougailconfig) super().__init__(config, rougailconfig)
def _instance_files(self, def get_data_files(self,
filevar: Dict, filevar: Dict,
destfile: str, destfile: str,
service_name: str, service_name: str,
service_type: str,
variable, variable,
idx: int, idx: int,
) -> tuple: ) -> tuple:
@ -88,10 +93,11 @@ class RougailSystemdTemplate(RougailBaseTemplate):
var = None var = None
return tmp_file, None, destfile, var return tmp_file, None, destfile, var
def _instance_overrides(self, def get_data_overrides(self,
filevar: Dict, filevar: Dict,
destfile, destfile,
service_name: str, service_name: str,
service_type: str,
*args, *args,
) -> tuple: ) -> tuple:
source = filevar['source'] source = filevar['source']
@ -99,12 +105,14 @@ class RougailSystemdTemplate(RougailBaseTemplate):
raise FileNotFound(_(f"File {source} does not exist.")) raise FileNotFound(_(f"File {source} does not exist."))
tmp_file = join(self.tmp_dir, source) tmp_file = join(self.tmp_dir, source)
service_name = filevar['name'] service_name = filevar['name']
return tmp_file, None, f'/systemd/system/{service_name}.service.d/rougail.conf', None destfile = f'/systemd/system/{service_name}.{service_type}.d/rougail.conf'
return tmp_file, None, destfile, None
def _instance_ip(self, def get_data_ip(self,
filevar: Dict, filevar: Dict,
ip, ip,
service_name: str, service_name: str,
service_type: str,
var: Any, var: Any,
idx: int, idx: int,
*args, *args,
@ -120,19 +128,49 @@ class RougailSystemdTemplate(RougailBaseTemplate):
elif ip: elif ip:
self.ip_per_service.append(ip) self.ip_per_service.append(ip)
def get_data_service(self,
servicevar: Dict,
info,
service_name: str,
service_type: str,
*args,
):
filename = f'{service_name}.{service_type}'
tmp_file = join(self.tmp_dir, filename)
var = None
destfile = f'/systemd/system/{filename}'
return tmp_file, None, destfile, var
def desactive_service(self, def desactive_service(self,
service_name: str, service_name: str,
service_type: str,
): ):
filename = f'{self.destinations_dir}/systemd/system/{service_name}.service' filename = f'{self.destinations_dir}/systemd/system/{service_name}.{service_type}'
makedirs(dirname(filename), exist_ok=True) makedirs(dirname(filename), exist_ok=True)
symlink('/dev/null', filename) symlink('/dev/null', filename)
def target_service(self,
service_name: str,
target_name: str,
service_type: str,
global_service: str,
):
filename = f'{self.destinations_dir}/systemd/system/{target_name}.target.wants/{service_name}.{service_type}'
makedirs(dirname(filename), exist_ok=True)
if global_service:
source_filename = f'{ROUGAIL_GLOBAL_SYSTEMD_FILE}/{service_name}.{service_type}'
else:
source_filename = f'{ROUGAIL_DEST}/systemd/system/{service_name}.{service_type}'
symlink(source_filename, filename)
def post_instance_service(self, def post_instance_service(self,
service_name: str, service_name: str,
service_type: str,
) -> None: # pragma: no cover ) -> None: # pragma: no cover
if self.ip_per_service is None: if self.ip_per_service is None:
return return
destfile = f'/systemd/system/{service_name}.service.d/rougail_ip.conf' destfile = f'/systemd/system/{service_name}.{service_type}.d/rougail_ip.conf'
destfilename = join(self.destinations_dir, destfile[1:]) destfilename = join(self.destinations_dir, destfile[1:])
makedirs(dirname(destfilename), exist_ok=True) makedirs(dirname(destfilename), exist_ok=True)
self.log.info(_(f"creole processing: '{destfilename}'")) self.log.info(_(f"creole processing: '{destfilename}'"))

View File

@ -243,7 +243,7 @@ class Common:
): ):
"""Populate variable parameters """Populate variable parameters
""" """
if param.type in ['number', 'boolean', 'nil', 'string', 'port']: if param.type in ['number', 'boolean', 'nil', 'string', 'port', 'choice']:
value = param.text value = param.text
if param.type == 'string' and value is not None: if param.type == 'string' and value is not None:
value = self.convert_str(value) value = self.convert_str(value)
@ -251,7 +251,11 @@ class Common:
if param.type == 'variable': if param.type == 'variable':
return self.build_option_param(param) return self.build_option_param(param)
if param.type == 'information': if param.type == 'information':
return f'ParamInformation("{param.text}", None)' if hasattr(self.elt, 'multi') and self.elt.multi:
default = []
else:
default = None
return f'ParamInformation("{param.text}", {default})'
if param.type == 'target_information': if param.type == 'target_information':
return f'ParamSelfInformation("{param.text}", None)' return f'ParamSelfInformation("{param.text}", None)'
if param.type == 'suffix': if param.type == 'suffix':
@ -294,13 +298,13 @@ class Variable(Common):
): ):
if hasattr(self.elt, 'opt'): if hasattr(self.elt, 'opt'):
keys['opt'] = self.elt.opt.reflector_object.get() keys['opt'] = self.elt.opt.reflector_object.get()
if hasattr(self.elt, 'values'): if hasattr(self.elt, 'choice'):
values = self.elt.values values = self.elt.choice
if values[0].type == 'variable': if values[0].type == 'variable':
value = values[0].name.reflector_object.get() value = values[0].name.reflector_object.get()
keys['values'] = f"Calculation(func.calc_value, Params((ParamOption({value}))))" keys['values'] = f"Calculation(func.calc_value, Params((ParamOption({value}))))"
elif values[0].type == 'function': elif values[0].type == 'function':
keys['values'] = self.calculation_value(self.elt.values[0], []) keys['values'] = self.calculation_value(values[0], [])
else: else:
keys['values'] = str(tuple([val.name for val in values])) keys['values'] = str(tuple([val.name for val in values]))
if hasattr(self.elt, 'multi') and self.elt.multi: if hasattr(self.elt, 'multi') and self.elt.multi:

View File

@ -76,6 +76,8 @@ class RougailUpgrade:
for filename in filenames: for filename in filenames:
xmlsrc = join(srcfolder, filename) xmlsrc = join(srcfolder, filename)
xmldst = join(dstfolder, filename) xmldst = join(dstfolder, filename)
if isfile(xmldst):
raise Exception(f'cannot update "{xmlsrc}" destination file "{xmldst}" already exists')
try: try:
parser = XMLParser(remove_blank_text=True) parser = XMLParser(remove_blank_text=True)
document = parse(xmlsrc, parser) document = parse(xmlsrc, parser)
@ -113,42 +115,64 @@ class RougailUpgrade:
variables = root.find('variables') variables = root.find('variables')
if variables is None: if variables is None:
return root return root
constraints = root.find('constraints')
if constraints is None:
return root
groups = []
for constraint in constraints:
if constraint.tag == 'group':
constraints.remove(constraint)
groups.append(constraint)
if not groups:
return root
paths = self._get_path_variables(variables, paths = self._get_path_variables(variables,
namespace == self.rougailconfig['variable_namespace'], namespace == self.rougailconfig['variable_namespace'],
namespace, namespace,
) )
constraints = root.find('constraints')
# convert schedule and schedulemod
for variable in paths.values():
variable = variable['variable']
if variable.tag != 'variable':
continue
if 'type' in variable.attrib and variable.attrib['type'] in ['schedule', 'schedulemod']:
if variable.attrib['type'] == 'schedule':
choices = ('none', 'daily', 'weekly', 'monthly')
else:
choices = ('pre', 'post')
variable.attrib['type'] = 'choice'
has_value = False
for value in variable:
if value.tag == 'value':
has_value = True
break
for name in choices:
choice = SubElement(variable, 'choice')
choice.text = name
if not has_value:
value = SubElement(variable, 'value')
value.text = choices[0]
variable.attrib['mandatory'] = 'True'
# convert group to leadership
groups = []
if constraints is not None:
for constraint in constraints:
if constraint.tag == 'group':
constraints.remove(constraint)
groups.append(constraint)
for group in groups: for group in groups:
if group.attrib['leader'] in paths: if group.attrib['leader'] in paths:
leader_obj = paths[group.attrib['leader']] leader_obj = paths[group.attrib['leader']]
#FIXME name peut avoir "." il faut le virer #FIXME name peut avoir "." il faut le virer
#FIXME si extra c'est un follower ! #FIXME si extra c'est un follower !
if 'name' in group.attrib: if 'name' in group.attrib:
name = group.attrib['name'] grpname = group.attrib['name']
if 'description' in group.attrib: if 'description' in group.attrib:
description = group.attrib['description'] description = group.attrib['description']
else: else:
description = name description = grpname
else: else:
name = leader_obj['variable'].attrib['name'] grpname = leader_obj['variable'].attrib['name']
if '.' in name: if '.' in grpname:
name = name.rsplit('.', 1)[-1] grpname = grpname.rsplit('.', 1)[-1]
if 'description' in group.attrib: if 'description' in group.attrib:
description = group.attrib['description'] description = group.attrib['description']
elif 'description' in leader_obj['variable'].attrib: elif 'description' in leader_obj['variable'].attrib:
description = leader_obj['variable'].attrib['description'] description = leader_obj['variable'].attrib['description']
else: else:
description = name description = grpname
family = SubElement(leader_obj['parent'], 'family', name=name, description=description, leadership="True") family = SubElement(leader_obj['parent'], 'family', name=grpname, description=description, leadership="True")
leader_obj['parent'].remove(leader_obj['variable']) leader_obj['parent'].remove(leader_obj['variable'])
family.append(leader_obj['variable']) family.append(leader_obj['variable'])
else: else:
@ -162,6 +186,7 @@ class RougailUpgrade:
follower_path = follower.text follower_path = follower.text
obj = paths[follower_path] obj = paths[follower_path]
family = SubElement(obj['parent'], 'family', name=leader_name, leadership="True") family = SubElement(obj['parent'], 'family', name=leader_name, leadership="True")
grpname = leader_name
for follower in group: for follower in group:
leader_name = group.attrib['leader'] leader_name = group.attrib['leader']
if '.' in leader_name: if '.' in leader_name:
@ -172,6 +197,73 @@ class RougailUpgrade:
follower_obj = paths[follower_path] follower_obj = paths[follower_path]
follower_obj['parent'].remove(follower_obj['variable']) follower_obj['parent'].remove(follower_obj['variable'])
family.append(follower_obj['variable']) family.append(follower_obj['variable'])
if '.' in follower_path:
new_path = follower_path.rsplit('.', 1)[0] + '.' + grpname + '.' + follower_path.rsplit('.', 1)[1]
paths[new_path] = paths[follower_path]
# convert choice option
valid_enums = []
if constraints is not None:
for constraint in constraints:
if constraint.tag == 'check' and constraint.attrib['name'] == 'valid_enum':
constraints.remove(constraint)
valid_enums.append(constraint)
for valid_enum in valid_enums:
targets = []
for target in valid_enum:
if target.tag != 'target':
continue
if target.text in paths:
# not in paths if it's optional
# but not check it
targets.append(paths[target.text]['variable'])
params = []
function_param = None
for param in valid_enum:
if param.tag != 'param':
continue
if 'type' in param.attrib and param.attrib['type'] == 'function':
function_param = param.text
continue
params.append(param)
first_choice = None
for target in targets:
if function_param is not None:
function = SubElement(target, 'choice', type='function', name=function_param)
for param in params:
if function_param is not None:
function.append(param)
else:
choice = SubElement(target, 'choice')
if first_choice is None:
first_choice = choice
choice.text = param.text
if 'type' not in param.attrib and param.text is None:
choice_type = 'nil'
elif 'type' in param.attrib:
choice_type = param.attrib['type']
elif 'type' in target.attrib:
choice_type = target.attrib['type']
else:
choice_type = 'string'
choice.attrib['type'] = choice_type
has_value = False
for target in targets:
if 'remove_check' in target.attrib:
target.attrib['remove_choice'] = target.attrib['remove_check']
for target in targets:
for value in target:
if value.tag == 'value':
has_value = True
if 'type' in target.attrib:
value.attrib['type'] = target.attrib['type']
if first_choice is not None and not has_value:
value = SubElement(target, 'value')
value.attrib['type'] = first_choice.attrib['type']
value.text = first_choice.text
for target in targets:
if 'remove_choice' not in target.attrib or target.attrib['remove_choice'] != 'True':
target.attrib['type'] = 'choice'
return root return root
def _get_path_variables(self, variables, is_variable_namespace, path, dico=None): def _get_path_variables(self, variables, is_variable_namespace, path, dico=None):
@ -182,6 +274,8 @@ class RougailUpgrade:
subpath = path + '.' subpath = path + '.'
else: else:
subpath = '' subpath = ''
if variable.tag not in ['variable', 'family']:
continue
subpath += variable.attrib['name'] subpath += variable.attrib['name']
if variable.tag == 'family': if variable.tag == 'family':
self._get_path_variables(variable, is_variable_namespace, subpath, dico) self._get_path_variables(variable, is_variable_namespace, subpath, dico)

View File

@ -2,15 +2,13 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True"/> <variable name="mode_conteneur_actif" type="string" description="No change" multi="True"/>
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum"> <fill name="calc_val">
<param>a</param> <param type="information">test_information</param>
<param>b</param>
<param>c</param>
<target>mode_conteneur_actif</target> <target>mode_conteneur_actif</target>
</check> </fill>
</constraints> </constraints>
</rougail> </rougail>

View File

@ -1,6 +1,8 @@
{ {
"rougail.general.mode_conteneur_actif": { "rougail.general.mode_conteneur_actif": {
"owner": "default", "owner": "default",
"value": "non" "value": [
"value"
]
} }
} }

View File

@ -0,0 +1,5 @@
{
"rougail.general.mode_conteneur_actif": [
"value"
]
}

View File

@ -1,6 +1,8 @@
{ {
"rougail.general.mode_conteneur_actif": { "rougail.general.mode_conteneur_actif": {
"owner": "default", "owner": "default",
"value": "non" "value": [
"value"
]
} }
} }

View File

@ -11,7 +11,7 @@ try:
from tiramisu3 import * from tiramisu3 import *
except: except:
from tiramisu import * from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", multi=True, default=[Calculation(func.calc_val, Params((ParamInformation("test_information", []))))], properties=frozenset({"normal"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"})) option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View File

@ -7,17 +7,16 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="number" description="enumvar" help="bla bla bla"/> <variable name="enumvar" type="choice" description="enumvar" help="bla bla bla">
<choice type="number">1</choice>
<choice type="number">2</choice>
<choice type="number">3</choice>
<value type="number">1</value>
</variable>
<variable name="test_variable" type="number" description="test variable"/> <variable name="test_variable" type="number" description="test variable"/>
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>1</param>
<param>2</param>
<param>3</param>
<target>enumvar</target>
</check>
<condition name="hidden_if_in" source="enumvar"> <condition name="hidden_if_in" source="enumvar">
<param>4</param> <param>4</param>
<target type="variable">test_variable</target> <target type="variable">test_variable</target>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="string" description="No change">
<value>tous</value> <value>tous</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="disabled_if_in" source="condition"> <condition name="disabled_if_in" source="condition">
<param type="variable">mode_conteneur_actif</param> <param type="variable">mode_conteneur_actif</param>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="string" description="No change">
<value>aucun</value> <value>aucun</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="disabled_if_in" source="condition"> <condition name="disabled_if_in" source="condition">
<param type="variable">mode_conteneur_actif</param> <param type="variable">mode_conteneur_actif</param>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="string" description="No change">
<value>non</value> <value>non</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="hidden_if_in" source="condition"> <condition name="hidden_if_in" source="condition">
<param>tous</param> <param>tous</param>
<param>authentifié</param> <param>authentifié</param>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True"> <variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value> <value>non</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="hidden_if_in" source="condition"> <condition name="hidden_if_in" source="condition">
<param>oui</param> <param>oui</param>
<param>non</param> <param>non</param>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="string" description="No change">
<value>tous</value> <value>tous</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="hidden_if_in" source="condition"> <condition name="hidden_if_in" source="condition">
<param type="variable">mode_conteneur_actif</param> <param type="variable">mode_conteneur_actif</param>
<target type="variable">mode_conteneur_actif2</target> <target type="variable">mode_conteneur_actif2</target>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="string" description="No change">
<value>non</value> <value>non</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="hidden_if_not_in" source="condition"> <condition name="hidden_if_not_in" source="condition">
<param>oui</param> <param>oui</param>
<param>non</param> <param>non</param>

View File

@ -2,8 +2,11 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>tous</value> <value type="string">tous</value>
<choice type="string">tous</choice>
<choice type="string">authentifié</choice>
<choice type="string">aucun</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True"> <variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value> <value>non</value>
@ -14,12 +17,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>tous</param>
<param>authentifié</param>
<param>aucun</param>
<target>condition</target>
</check>
<condition name="mandatory_if_not_in" source="condition"> <condition name="mandatory_if_not_in" source="condition">
<param>oui</param> <param>oui</param>
<param>non</param> <param>non</param>

View File

@ -7,18 +7,14 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" help="bla bla bla"> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<value>c</value> <value type="string">c</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
<choice type="string">é</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<param>é</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,15 +7,12 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="enumvar"> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<value>non</value> <value type="string">b</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param type="number">1</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="enumfam">
<variable name="enumvar" redefine="True">
<value type="string">c</value>
<choice type="string">c</choice>
</variable>
</family>
</variables>
<constraints/>
</rougail>

View File

@ -0,0 +1,10 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"rougail.enumfam.enumvar": {
"owner": "default",
"value": "c"
}
}

View File

@ -0,0 +1,4 @@
{
"rougail.general.mode_conteneur_actif": "non",
"rougail.enumfam.enumvar": "c"
}

View File

@ -0,0 +1,10 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"rougail.enumfam.enumvar": {
"owner": "default",
"value": "c"
}
}

View File

@ -0,0 +1,20 @@
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_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', 'c'), default="c", properties=frozenset({"expert", "mandatory"}))
option_5.impl_set_information('help', "bla bla bla")
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View File

@ -7,17 +7,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" help="bla bla bla"> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<value>c</value> <value type="string">c</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,17 +7,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" mandatory="False"> <variable name="enumvar" mandatory="False" type="choice">
<value>c</value> <value>c</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,26 +7,19 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar2" type="string" description="multi"> <variable name="enumvar2" type="choice" description="multi">
<value>c</value> <value type="string">c</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
</variable> </variable>
<variable name="enumvar" type="string" description="multi" help="bla bla bla"> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<value>c</value> <value type="string">c</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>enumvar</target>
</check>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>enumvar2</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -2,16 +2,12 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" redefine="True" remove_check="True"> <variable name="enumvar" redefine="True" remove_check="True" remove_choice="True">
<value>c</value> <value>c</value>
<choice type="string">a</choice>
<choice type="string">c</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>c</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,17 +7,15 @@
</variable> </variable>
<family name="leader" description="leader" leadership="True"> <family name="leader" description="leader" leadership="True">
<variable name="leader" type="string" description="leader" multi="True"/> <variable name="leader" type="string" description="leader" multi="True"/>
<variable name="follower1" type="string" description="follower1"/> <variable name="follower1" type="choice" description="follower1">
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
<value type="string">a</value>
</variable>
<variable name="follower2" type="string" description="follower2"/> <variable name="follower2" type="string" description="follower2"/>
</family> </family>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>follower1</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -8,15 +8,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" mandatory="True"/> <variable name="enumvar" type="choice" description="multi" mandatory="True">
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
<value type="string">a</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -5,15 +5,13 @@
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="string" description="No change">
<value>non</value> <value>non</value>
</variable> </variable>
<variable name="multi" type="string" description="multi" multi="True"/> <variable name="multi" type="choice" description="multi" multi="True">
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
<value type="string">a</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>multi</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,17 +7,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" help="bla bla bla" mandatory="False"> <variable name="enumvar" type="choice" description="multi" help="bla bla bla" mandatory="False">
<value>b</value> <value type="string">b</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="nil"/>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param/>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -13,7 +13,7 @@ except:
from tiramisu import * from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "mandatory"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"})) option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"expert"}))
option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', '', None), default="b", properties=frozenset({"expert"})) option_5 = ChoiceOption(name="enumvar", doc="multi", values=('a', 'b', None), default="b", properties=frozenset({"expert"}))
option_5.impl_set_information('help', "bla bla bla") option_5.impl_set_information('help', "bla bla bla")
option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"})) option_4 = OptionDescription(name="enumfam", doc="enumfam", children=[option_5], properties=frozenset({"expert"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4]) option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])

View File

@ -7,15 +7,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="number" description="enumvar" help="bla bla bla"/> <variable name="enumvar" type="choice" description="enumvar" help="bla bla bla">
<choice type="number">1</choice>
<choice type="number">2</choice>
<choice type="number">3</choice>
<value type="number">1</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>1</param>
<param>2</param>
<param>3</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,17 +7,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="number" description="enumvar" help="bla bla bla"> <variable name="enumvar" type="choice" description="enumvar" help="bla bla bla">
<value>3</value> <value type="number">3</value>
<choice type="number">1</choice>
<choice type="number">2</choice>
<choice type="number">3</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>1</param>
<param>2</param>
<param>3</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,13 +7,11 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" help="bla bla bla"/> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<choice type="nil"/>
<value type="nil"/>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param type="nil"/>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,13 +7,11 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" help="bla bla bla"/> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<choice type="nil"/>
<value type="nil"/>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param type="nil"/>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,15 +7,13 @@
</variable> </variable>
</family> </family>
<family name="enumfam" mode="expert"> <family name="enumfam" mode="expert">
<variable name="enumvar" type="string" description="multi" help="bla bla bla"/> <variable name="enumvar" type="choice" description="multi" help="bla bla bla">
<choice type="string">quote'</choice>
<choice type="string">quote"</choice>
<choice type="string">quote"'</choice>
<value type="string">quote'</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>quote'</param>
<param>quote"</param>
<param>quote"'</param>
<target>enumvar</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -2,17 +2,13 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="choice" description="No change">
<value>b</value> <value type="string">b</value>
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>mode_conteneur_actif</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -7,8 +7,10 @@
</services> </services>
<variables> <variables>
<family name="general"> <family name="general">
<variable name="condition" type="string" description="No change"> <variable name="condition" type="choice" description="No change">
<value>non</value> <value type="string">non</value>
<choice type="string">non</choice>
<choice type="string">statique</choice>
</variable> </variable>
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True"> <variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value> <value>non</value>
@ -19,11 +21,6 @@
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>non</param>
<param>statique</param>
<target>condition</target>
</check>
<condition name="disabled_if_not_in" source="condition"> <condition name="disabled_if_not_in" source="condition">
<param>statique</param> <param>statique</param>
<target type="filelist">afilllist</target> <target type="filelist">afilllist</target>

View File

@ -2,17 +2,14 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="var" type="number" description="New variable"> <variable name="var" type="choice" description="New variable">
<value>9</value> <value type="number">9</value>
<choice type="function" name="trange">
<param type="number">0</param>
<param type="number">10</param>
</choice>
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param type="function">trange</param>
<param type="number">0</param>
<param type="number">10</param>
<target>var</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -2,8 +2,9 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif" type="string" description="No change"> <variable name="mode_conteneur_actif" type="choice" description="No change">
<value>a</value> <value type="string">a</value>
<choice type="variable">var</choice>
</variable> </variable>
<variable name="var" type="string" description="New variable" multi="True"> <variable name="var" type="string" description="New variable" multi="True">
<value>a</value> <value>a</value>
@ -12,10 +13,5 @@
</variable> </variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param type="variable">var</param>
<target>mode_conteneur_actif</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general">
<variable name="varname" type="string" description="No change" multi="True">
<value>val1</value>
<value>val2</value>
</variable>
</family>
<family name="dyn" dynamic="varname">
<variable name="vardyn" type="string" description="No change"/>
<family name="leadership" leadership="True">
<variable name="leader" type="string" description="leader" multi="True"/>
<variable name="follower1" type="string" description="follower1"/>
<variable name="follower2" type="string" description="follower2"/>
</family>
</family>
</variables>
</rougail>

View File

@ -0,0 +1,41 @@
{
"rougail.general.varname": {
"owner": "default",
"value": [
"val1",
"val2"
]
},
"rougail.dynval1.vardynval1": {
"owner": "default",
"value": null
},
"rougail.dynval1.leadershipval1.leaderval1": {
"owner": "default",
"value": []
},
"rougail.dynval1.leadershipval1.follower1val1": {
"owner": [],
"value": []
},
"rougail.dynval1.leadershipval1.follower2val1": {
"owner": [],
"value": []
},
"rougail.dynval2.vardynval2": {
"owner": "default",
"value": null
},
"rougail.dynval2.leadershipval2.leaderval2": {
"owner": "default",
"value": []
},
"rougail.dynval2.leadershipval2.follower1val2": {
"owner": [],
"value": []
},
"rougail.dynval2.leadershipval2.follower2val2": {
"owner": [],
"value": []
}
}

View File

@ -0,0 +1,10 @@
{
"rougail.general.varname": [
"val1",
"val2"
],
"rougail.dynval1.vardynval1": null,
"rougail.dynval1.leadershipval1.leaderval1": [],
"rougail.dynval2.vardynval2": null,
"rougail.dynval2.leadershipval2.leaderval2": []
}

View File

@ -0,0 +1,41 @@
{
"rougail.general.varname": {
"owner": "default",
"value": [
"val1",
"val2"
]
},
"rougail.dynval1.vardynval1": {
"owner": "default",
"value": null
},
"rougail.dynval1.leadershipval1.leaderval1": {
"owner": "default",
"value": []
},
"rougail.dynval1.leadershipval1.follower1val1": {
"owner": [],
"value": []
},
"rougail.dynval1.leadershipval1.follower2val1": {
"owner": [],
"value": []
},
"rougail.dynval2.vardynval2": {
"owner": "default",
"value": null
},
"rougail.dynval2.leadershipval2.leaderval2": {
"owner": "default",
"value": []
},
"rougail.dynval2.leadershipval2.follower1val2": {
"owner": [],
"value": []
},
"rougail.dynval2.leadershipval2.follower2val2": {
"owner": [],
"value": []
}
}

View File

@ -0,0 +1,24 @@
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="varname", doc="No change", multi=True, default=['val1', 'val2'], default_multi="val1", properties=frozenset({"mandatory", "normal"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"}))
option_5 = StrOption(name="vardyn", doc="No change", properties=frozenset({"normal"}))
option_7 = StrOption(name="leader", doc="leader", multi=True)
option_8 = StrOption(name="follower1", doc="follower1", multi=True, properties=frozenset({"normal"}))
option_9 = StrOption(name="follower2", doc="follower2", multi=True, properties=frozenset({"normal"}))
option_6 = Leadership(name="leadership", doc="leadership", children=[option_7, option_8, option_9], properties=frozenset({"normal"}))
option_4 = ConvertDynOptionDescription(name="dyn", doc="dyn", suffixes=Calculation(func.calc_value, Params((ParamOption(option_3, notraisepropertyerror=True)))), children=[option_5, option_6], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_4])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View File

@ -10,16 +10,15 @@
<variable name="mode_conteneur_actif2" type="string" description="No change"> <variable name="mode_conteneur_actif2" type="string" description="No change">
<value>non</value> <value>non</value>
</variable> </variable>
<variable name="mode_conteneur_actif3" type="string" description="No change"/> <variable name="mode_conteneur_actif3" type="choice" description="No change">
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
<value type="string">a</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>mode_conteneur_actif3</target>
</check>
<condition name="disabled_if_in" source="mode_conteneur_actif3"> <condition name="disabled_if_in" source="mode_conteneur_actif3">
<param>d</param> <param>d</param>
<target type="variable">mode_conteneur_actif</target> <target type="variable">mode_conteneur_actif</target>

View File

@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general">
<variable name="mode_conteneur_actif" redefine="True" remove_check="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View File

@ -1,3 +0,0 @@
{
"rougail.general.mode_conteneur_actif": "non"
}

View File

@ -2,15 +2,13 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif" type="string" description="Redefine description" hidden="True"/> <variable name="mode_conteneur_actif" type="choice" description="Redefine description" hidden="True">
<choice type="string">a</choice>
<choice type="string">b</choice>
<choice type="string">c</choice>
<value type="string">a</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<param>c</param>
<target>mode_conteneur_actif</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -2,14 +2,12 @@
<rougail version="0.10"> <rougail version="0.10">
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif" redefine="True" remove_check="True"/> <variable name="mode_conteneur_actif" redefine="True" remove_check="True" remove_choice="True">
<choice type="string">a</choice>
<choice type="string">b</choice>
<value type="string">a</value>
</variable>
</family> </family>
</variables> </variables>
<constraints> <constraints/>
<check name="valid_enum">
<param>a</param>
<param>b</param>
<target>mode_conteneur_actif</target>
</check>
</constraints>
</rougail> </rougail>

View File

@ -5,9 +5,17 @@
<variable name="description" type="string"> <variable name="description" type="string">
<value>Exportation de la base de ejabberd</value> <value>Exportation de la base de ejabberd</value>
</variable> </variable>
<variable name="day" type="schedule"/> <variable name="day" type="choice" mandatory="True">
<variable name="mode" type="schedulemod"> <choice>none</choice>
<choice>daily</choice>
<choice>weekly</choice>
<choice>monthly</choice>
<value>none</value>
</variable>
<variable name="mode" type="choice" mandatory="True">
<value>pre</value> <value>pre</value>
<choice>pre</choice>
<choice>post</choice>
</variable> </variable>
</family> </family>
</variables> </variables>

View File

@ -5,9 +5,17 @@
<variable name="description" type="string"> <variable name="description" type="string">
<value>Exportation de la base de ejabberd</value> <value>Exportation de la base de ejabberd</value>
</variable> </variable>
<variable name="day" type="schedule" help="Test help"/> <variable name="day" type="choice" help="Test help" mandatory="True">
<variable name="mode" type="schedulemod"> <choice>none</choice>
<choice>daily</choice>
<choice>weekly</choice>
<choice>monthly</choice>
<value>none</value>
</variable>
<variable name="mode" type="choice" mandatory="True">
<value>pre</value> <value>pre</value>
<choice>pre</choice>
<choice>post</choice>
</variable> </variable>
</family> </family>
</variables> </variables>

Some files were not shown because too many files have changed in this diff Show More