remove condition not only a target

This commit is contained in:
Emmanuel Garette 2020-12-22 20:17:32 +01:00
parent 80b7f1b083
commit 90bd72de69
16 changed files with 45 additions and 66 deletions

View File

@ -765,6 +765,7 @@ class ConstraintAnnotator:
if target.type == 'variable': if target.type == 'variable':
variable = self.objectspace.paths.get_variable_obj(target.name) variable = self.objectspace.paths.get_variable_obj(target.name)
family = self.objectspace.paths.get_family_obj(target.name.rsplit('.', 1)[0]) family = self.objectspace.paths.get_family_obj(target.name.rsplit('.', 1)[0])
# it's a leader, so apply property to leadership
if isinstance(family, self.objectspace.Leadership) and family.name == variable.name: if isinstance(family, self.objectspace.Leadership) and family.name == variable.name:
return family, family.variable return family, family.variable
return variable, [variable] return variable, [variable]
@ -927,27 +928,28 @@ class ConstraintAnnotator:
inverse = condition.name.endswith('_if_not_in') inverse = condition.name.endswith('_if_not_in')
actions = self._get_condition_actions(condition.name) actions = self._get_condition_actions(condition.name)
for param in condition.param: for param in condition.param:
if hasattr(param, 'text'): text = getattr(param, 'text', None)
param = param.text
else:
param = None
for target in condition.target: for target in condition.target:
leader_or_variable, variables = self._get_family_variables_from_target(target) leader_or_variable, variables = self._get_family_variables_from_target(target)
# if option is already disable, do not apply disable_if_in # if option is already disable, do not apply disable_if_in
if hasattr(leader_or_variable, actions[0]) and getattr(leader_or_variable, actions[0]) is True: # check only the first action (example of multiple actions: 'hidden', 'frozen', 'force_default_on_freeze')
main_action = actions[0]
if getattr(leader_or_variable, main_action, False) is True:
continue continue
for idx, action in enumerate(actions): for idx, action in enumerate(actions):
prop = self.objectspace.property_(leader_or_variable.xmlfiles) prop = self.objectspace.property_(leader_or_variable.xmlfiles)
prop.type = 'calculation' prop.type = 'calculation'
prop.inverse = inverse prop.inverse = inverse
prop.source = condition.source prop.source = condition.source
prop.expected = param prop.expected = text
prop.name = action prop.name = action
if idx == 0: if idx == 0:
# main action is for the variable or family
if not hasattr(leader_or_variable, 'property'): if not hasattr(leader_or_variable, 'property'):
leader_or_variable.property = [] leader_or_variable.property = []
leader_or_variable.property.append(prop) leader_or_variable.property.append(prop)
else: else:
# other actions are set to the variable or children of family
for variable in variables: for variable in variables:
if not hasattr(variable, 'property'): if not hasattr(variable, 'property'):
variable.property = [] variable.property = []

View File

@ -441,16 +441,12 @@ class CreoleObjSpace:
self.space.constraints.check.pop(idx) # pylint: disable=E1101 self.space.constraints.check.pop(idx) # pylint: disable=E1101
def remove_condition(self, name): # pylint: disable=C0111 def remove_condition(self, name): # pylint: disable=C0111
remove_conditions = []
for idx, condition in enumerate(self.space.constraints.condition): # pylint: disable=E1101 for idx, condition in enumerate(self.space.constraints.condition): # pylint: disable=E1101
remove_targets = [] if condition.source == name:
if hasattr(condition, 'target'): remove_conditions.append(idx)
for target_idx, target in enumerate(condition.target): for idx in remove_conditions:
if target.name == name: del self.space.constraints.condition[idx]
remove_targets.append(target_idx)
remove_targets = list(set(remove_targets))
remove_targets.sort(reverse=True)
for idx in remove_targets:
del condition.target[idx]
def add_to_tree_structure(self, def add_to_tree_structure(self,
variableobj, variableobj,

View File

@ -26,7 +26,7 @@
<param type="variable">mode_conteneur_actif1</param> <param type="variable">mode_conteneur_actif1</param>
</check> </check>
<check name="valid_differ" target="mode_conteneur_actif3"> <check name="valid_differ" target="mode_conteneur_actif3">
<param type="variable">mode_conteneur_actif2</param> <param type="variable">mode_conteneur_actif1</param>
</check> </check>
</constraints> </constraints>

View File

@ -5,9 +5,7 @@
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif3" redefine="True"> <variable name="mode_conteneur_actif3" redefine="True"/>
<value>oui</value>
</variable>
</family> </family>
<separators/> <separators/>
</variables> </variables>

View File

@ -1,8 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<rougail> <rougail>
<services/>
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif" type="oui/non" description="No change"> <variable name="mode_conteneur_actif" type="oui/non" description="No change">
@ -11,26 +8,22 @@
<variable name="condition" type="oui/non" description="No change"> <variable name="condition" type="oui/non" description="No change">
<value>non</value> <value>non</value>
</variable> </variable>
<variable name="mode_conteneur_actif1" type="oui/non" description="No change" hidden="True"> <variable name="mode_conteneur_actif1" type="oui/non" description="No change">
<value>non</value> <value>non</value>
</variable> </variable>
<variable name="mode_conteneur_actif2" type="oui/non" description="No change" hidden="True"> <variable name="mode_conteneur_actif2" type="oui/non" description="No change">
<value>non</value> <value>non</value>
</variable> </variable>
</family> </family>
<separators/>
</variables> </variables>
<constraints> <constraints>
<condition name="disabled_if_in" source="condition"> <condition fallback="True" name="disabled_if_in" source="condition">
<param>oui</param> <param>oui</param>
<target type="variable">mode_conteneur_actif1</target> <target type="variable">mode_conteneur_actif1</target>
<target type="variable">mode_conteneur_actif2</target> <target type="variable" optional="True">mode_conteneur_actif2</target>
</condition> </condition>
</constraints> </constraints>
<help/>
</rougail> </rougail>
<!-- vim: ts=4 sw=4 expandtab <!-- vim: ts=4 sw=4 expandtab
--> -->

View File

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

View File

@ -10,8 +10,8 @@ except:
from rougail.tiramisu import ConvertDynOptionDescription from rougail.tiramisu import ConvertDynOptionDescription
option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('oui', 'non')) option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_5 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non')) option_5 = ChoiceOption(properties=frozenset({'mandatory', 'normal', Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_4, todict=True), 'expected': ParamValue('oui')}))}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_6 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non')) option_6 = ChoiceOption(properties=frozenset({'mandatory', 'normal', Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_4, todict=True), 'expected': ParamValue('oui')}))}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4, option_5, option_6]) option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4, option_5, option_6])
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

@ -5,7 +5,7 @@
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif1" redefine="True" remove_condition="True"/> <variable name="condition" redefine="True" remove_condition="True"/>
</family> </family>
<separators/> <separators/>
</variables> </variables>

View File

@ -11,7 +11,7 @@ from rougail.tiramisu import ConvertDynOptionDescription
option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('oui', 'non')) option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_5 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non')) option_5 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_6 = ChoiceOption(properties=frozenset({'mandatory', 'normal', Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_4, todict=True), 'expected': ParamValue('oui')}))}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non')) option_6 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4, option_5, option_6]) option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4, option_5, option_6])
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

@ -1,19 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<services/>
<variables>
<family name="general">
<variable name="mode_conteneur_actif1" redefine="True" remove_condition="True"/>
<variable name="mode_conteneur_actif2" redefine="True" remove_condition="True"/>
</family>
<separators/>
</variables>
<constraints>
</constraints>
<help/>
</rougail>

View File

@ -1,18 +1,8 @@
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
<rougail> <rougail>
<services/>
<variables> <variables>
<family name="general"> <family name="general">
<variable name="mode_conteneur_actif1" redefine="True" remove_condition="True"/> <variable name="condition" redefine="True" remove_condition="True"/>
</family> </family>
<separators/>
</variables> </variables>
<constraints>
</constraints>
<help/>
</rougail> </rougail>

View File

@ -12,7 +12,7 @@ option_7 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen
option_3 = ChoiceOption(properties=frozenset({'auto_freeze', 'basic', 'force_store_value', 'mandatory', Calculation(calc_value, Params(ParamValue('auto_frozen'), kwargs={'condition': ParamOption(option_7, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non')) option_3 = ChoiceOption(properties=frozenset({'auto_freeze', 'basic', 'force_store_value', 'mandatory', Calculation(calc_value, Params(ParamValue('auto_frozen'), kwargs={'condition': ParamOption(option_7, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('oui', 'non')) option_4 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='condition', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_5 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non')) option_5 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif1', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_6 = ChoiceOption(properties=frozenset({'mandatory', 'normal', Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_4, todict=True), 'expected': ParamValue('oui')}))}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non')) option_6 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif2', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'basic'}), children=[option_3, option_4, option_5, option_6, option_7]) option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'basic'}), children=[option_3, option_4, option_5, option_6, option_7])
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

@ -28,7 +28,7 @@ excludes = set([])
#excludes = set(['01base_file_utfchar']) #excludes = set(['01base_file_utfchar'])
test_ok -= excludes test_ok -= excludes
test_raise -= excludes test_raise -= excludes
#test_ok = ['10leadership_autoleader'] #test_ok = ['40condition_base_add']
#test_raise = [] #test_raise = []
ORI_DIR = getcwd() ORI_DIR = getcwd()