refactor
This commit is contained in:
parent
9fcd72d459
commit
7d032a72b2
@ -933,13 +933,8 @@ class SpaceAnnotator(object):
|
||||
def filter_targets(self): # pylint: disable=C0111
|
||||
for condition_idx, condition in enumerate(self.space.constraints.condition):
|
||||
namespace = condition.namespace
|
||||
del_idx = []
|
||||
for idx, target in enumerate(condition.target):
|
||||
if target.type == 'variable':
|
||||
if (hasattr(target, 'optional') and target.optional is True and
|
||||
not self.paths.path_is_defined(target.name)):
|
||||
del_idx.append(idx)
|
||||
continue
|
||||
if condition.source == target.name:
|
||||
raise CreoleDictConsistencyError(_('target name and source name must be different: {}').format(condition.source))
|
||||
target.name = self.paths.get_variable_path(target.name, namespace)
|
||||
@ -948,10 +943,6 @@ class SpaceAnnotator(object):
|
||||
target.name = self.paths.get_family_path(target.name, namespace)
|
||||
except KeyError:
|
||||
raise CreoleDictConsistencyError(_('cannot found family {}').format(target.name))
|
||||
del_idx = list(set(del_idx))
|
||||
del_idx.sort(reverse=True)
|
||||
for idx in del_idx:
|
||||
condition.target.pop(idx)
|
||||
|
||||
def convert_xxxlist_to_variable(self): # pylint: disable=C0111
|
||||
# transform *list to variable or family
|
||||
@ -1001,10 +992,11 @@ class SpaceAnnotator(object):
|
||||
if target.type.endswith('list') and condition.name not in ['disabled_if_in', 'disabled_if_not_in']:
|
||||
raise CreoleDictConsistencyError(_(f'target in condition for {target.type} not allow in {condition.name}'))
|
||||
|
||||
def check_condition_fallback_not_exists(self):
|
||||
def check_condition_fallback_optional(self):
|
||||
# a condition with a fallback **and** the source variable doesn't exist
|
||||
remove_conditions = []
|
||||
for idx, condition in enumerate(self.space.constraints.condition):
|
||||
remove_targets = []
|
||||
if condition.fallback is True and not self.paths.path_is_defined(condition.source):
|
||||
for target in condition.target:
|
||||
if target.type in ['variable', 'family']:
|
||||
@ -1033,12 +1025,19 @@ class SpaceAnnotator(object):
|
||||
variable.value[0].name = False
|
||||
del self.objectspace.list_conditions[listname][target.name]
|
||||
remove_conditions.append(idx)
|
||||
for idx, target in enumerate(condition.target):
|
||||
if target.optional is True and not self.paths.path_is_defined(target.name):
|
||||
remove_targets.append(idx)
|
||||
remove_targets = list(set(remove_targets))
|
||||
remove_targets.sort(reverse=True)
|
||||
for idx in remove_targets:
|
||||
condition.target.pop(idx)
|
||||
remove_conditions = list(set(remove_conditions))
|
||||
remove_conditions.sort(reverse=True)
|
||||
for idx in remove_conditions:
|
||||
self.space.constraints.condition.pop(idx)
|
||||
|
||||
def check_choice_option_condition(self, force_remove_targets):
|
||||
def check_choice_option_condition(self):
|
||||
# remove condition for ChoiceOption that don't have param
|
||||
remove_conditions = []
|
||||
for condition_idx, condition in enumerate(self.space.constraints.condition):
|
||||
@ -1060,6 +1059,7 @@ class SpaceAnnotator(object):
|
||||
for idx in remove_param:
|
||||
del condition.param[idx]
|
||||
if condition.param == []:
|
||||
remove_targets = []
|
||||
for target in condition.target:
|
||||
if target.name.startswith(f'{VARIABLE_NAMESPACE}.'):
|
||||
name = target.name.split('.')[-1]
|
||||
@ -1071,29 +1071,24 @@ class SpaceAnnotator(object):
|
||||
variable = self.paths.get_family_obj(name)
|
||||
if condition.name == 'disabled_if_not_in':
|
||||
variable.disabled = True
|
||||
force_remove_targets.setdefault(condition.name,
|
||||
[]).append(target.name)
|
||||
elif condition.name == 'hidden_if_not_in':
|
||||
variable.hidden = True
|
||||
force_remove_targets.setdefault(condition.name,
|
||||
[]).append(target.name)
|
||||
elif condition.name == 'mandatory_if_not_in':
|
||||
variable.mandatory = True
|
||||
force_remove_targets.setdefault(condition.name,
|
||||
[]).append(target.name)
|
||||
remove_targets = list(set(remove_targets))
|
||||
remove_targets.sort(reverse=True)
|
||||
for target_idx in remove_targets:
|
||||
condition.target.pop(target_idx)
|
||||
remove_conditions.append(condition_idx)
|
||||
remove_conditions = list(set(remove_conditions))
|
||||
remove_conditions.sort(reverse=True)
|
||||
for idx in remove_conditions:
|
||||
self.space.constraints.condition.pop(idx)
|
||||
|
||||
def manage_variable_property(self, force_remove_targets):
|
||||
def manage_variable_property(self):
|
||||
for condition in self.space.constraints.condition:
|
||||
remove_targets = []
|
||||
#parse each variable and family
|
||||
for target_idx, target in enumerate(condition.target):
|
||||
if target.name in force_remove_targets.get(condition.name, []):
|
||||
remove_targets.append(target_idx)
|
||||
if target.name.startswith(f'{VARIABLE_NAMESPACE}.'):
|
||||
name = target.name.split('.')[-1]
|
||||
else:
|
||||
@ -1112,11 +1107,6 @@ class SpaceAnnotator(object):
|
||||
if condition.name in ['mandatory_if_in', 'mandatory_if_not_in']:
|
||||
self.force_not_mandatory.append(target.name)
|
||||
|
||||
remove_targets = list(set(remove_targets))
|
||||
remove_targets.sort(reverse=True)
|
||||
for target_idx in remove_targets:
|
||||
condition.target.pop(target_idx)
|
||||
|
||||
def remove_condition_with_empty_target(self):
|
||||
remove_conditions = []
|
||||
for condition_idx, condition in enumerate(self.space.constraints.condition):
|
||||
@ -1130,15 +1120,14 @@ class SpaceAnnotator(object):
|
||||
def filter_condition(self): # pylint: disable=C0111
|
||||
if not hasattr(self.space, 'constraints') or not hasattr(self.space.constraints, 'condition'):
|
||||
return
|
||||
force_remove_targets = {}
|
||||
self.check_condition()
|
||||
self.check_params()
|
||||
self.check_target()
|
||||
self.check_condition_fallback_not_exists()
|
||||
self.check_condition_fallback_optional()
|
||||
self.filter_targets()
|
||||
self.convert_xxxlist_to_variable()
|
||||
self.check_choice_option_condition(force_remove_targets)
|
||||
self.manage_variable_property(force_remove_targets)
|
||||
self.check_choice_option_condition()
|
||||
self.manage_variable_property()
|
||||
self.remove_condition_with_empty_target()
|
||||
for condition in self.space.constraints.condition:
|
||||
inverse = condition.name.endswith('_if_not_in')
|
||||
|
@ -25,6 +25,7 @@
|
||||
</variable>
|
||||
<variable doc="activate" multi="False" name="activate" type="boolean">
|
||||
<property>disabled</property>
|
||||
<property expected="oui" inverse="True" source="rougail.general.mode_conteneur_actif2" type="calculation">disabled</property>
|
||||
<value>True</value>
|
||||
</variable>
|
||||
</family>
|
||||
|
33
tests/flattener_dicos/80hidden_if_in_filelist/00-base.xml
Normal file
33
tests/flattener_dicos/80hidden_if_in_filelist/00-base.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
|
||||
<services>
|
||||
<service name="test">
|
||||
<file name="/tmp/file1" filelist="afilllist"/>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
<variables>
|
||||
<family name="general">
|
||||
<variable name="mode_conteneur_actif" type="oui/non" description="No change" hidden="True">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
<variable name="condition" type="oui/non" description="No change">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
</family>
|
||||
<separators/>
|
||||
</variables>
|
||||
|
||||
<constraints>
|
||||
<condition name="hidden_if_in" source="activer_clam" fallback="True">
|
||||
<param>non</param>
|
||||
<target type="filelist">afilllist</target>
|
||||
</condition>
|
||||
</constraints>
|
||||
|
||||
<help/>
|
||||
|
||||
</rougail>
|
||||
<!-- vim: ts=4 sw=4 expandtab
|
||||
-->
|
Loading…
Reference in New Issue
Block a user