From 1dcdbd474db776bdb0876254cff6a8eec256e0ad Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 30 Jan 2021 15:19:18 +0100 Subject: [PATCH] add multiple disable_if_in support --- src/rougail/annotator/condition.py | 41 +++++++++++-------- .../00-base.xml | 33 +++++++++++++++ .../__init__.py | 0 .../makedict/base.json | 1 + .../tiramisu/__init__.py | 0 .../tiramisu/base.py | 32 +++++++++++++++ .../00-base.xml | 33 +++++++++++++++ .../__init__.py | 0 .../makedict/base.json | 1 + .../tiramisu/__init__.py | 0 .../tiramisu/base.py | 32 +++++++++++++++ .../00-base.xml | 2 +- .../tiramisu/base.py | 4 +- .../tiramisu/base.py | 2 +- .../80hidden_if_in_filelist/00-base.xml | 3 -- 15 files changed, 159 insertions(+), 25 deletions(-) create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param/00-base.xml create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param/__init__.py create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param/makedict/base.json create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/__init__.py create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param_disabled/00-base.xml create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param_disabled/__init__.py create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param_disabled/makedict/base.json create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/__init__.py create mode 100644 tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py diff --git a/src/rougail/annotator/condition.py b/src/rougail/annotator/condition.py index 5d9eff25..0d05d34a 100644 --- a/src/rougail/annotator/condition.py +++ b/src/rougail/annotator/condition.py @@ -220,22 +220,19 @@ class ConditionAnnotator: listvar.default = self.force_service_value[target.name] continue value = condition.name != 'disabled_if_in' - if len(condition.param) != 1: - xmlfiles = self.objectspace.display_xmlfiles(condition.xmlfiles) - msg = _(f'a condition with "{listname}" can only have ' - f'only have only on param') - raise DictConsistencyError(msg, 35) from err if listvar.path in fills: fill = fills[listvar.path] - fill.index += 1 + or_needed = True + for param in fill.param: + if hasattr(param, 'name') and param.name == 'condition_operator': + or_needed = False + break else: fill = self.objectspace.fill(target.xmlfiles) fill.target = listvar.path fill.name = 'calc_value' fill.namespace = 'services' - fill.index = 0 - if not hasattr(self.objectspace.space, 'constraints'): - self.objectspace.space.constraints = self.objectspace.constraints(elt.xmlfiles) + fill.index = -1 if not hasattr(self.objectspace.space.constraints, 'fill'): self.objectspace.space.constraints.fill = [] self.objectspace.space.constraints.fill.append(fill) @@ -248,15 +245,23 @@ class ConditionAnnotator: param2.text = not value param2.type = 'boolean' fill.param = [param1, param2] - param3 = self.objectspace.param(target.xmlfiles) - param3.name = f'condition_{fill.index}' - param3.type = 'variable' - param3.text = condition.source - fill.param.append(param3) - param4 = self.objectspace.param(target.xmlfiles) - param4.name = f'expected_{fill.index}' - param4.text = getattr(condition.param[0], 'text', None) - fill.param.append(param4) + or_needed = len(condition.param) != 1 + for param in condition.param: + fill.index += 1 + param3 = self.objectspace.param(target.xmlfiles) + param3.name = f'condition_{fill.index}' + param3.type = 'variable' + param3.text = condition.source + fill.param.append(param3) + param4 = self.objectspace.param(target.xmlfiles) + param4.name = f'expected_{fill.index}' + param4.text = getattr(param, 'text', None) + fill.param.append(param4) + if or_needed: + param5 = self.objectspace.param(target.xmlfiles) + param5.name = 'condition_operator' + param5.text = 'OR' + fill.param.append(param5) remove_targets.append(target_idx) remove_targets.sort(reverse=True) for target_idx in remove_targets: diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param/00-base.xml b/tests/dictionaries/10load_disabled_if_in_multi_param/00-base.xml new file mode 100644 index 00000000..37cd891a --- /dev/null +++ b/tests/dictionaries/10load_disabled_if_in_multi_param/00-base.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + non + + + + + + + + + oui + maybe + mode_conteneur_actif + mode_conteneur_actif2 + afilllist + + + + diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param/__init__.py b/tests/dictionaries/10load_disabled_if_in_multi_param/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param/makedict/base.json b/tests/dictionaries/10load_disabled_if_in_multi_param/makedict/base.json new file mode 100644 index 00000000..77bac874 --- /dev/null +++ b/tests/dictionaries/10load_disabled_if_in_multi_param/makedict/base.json @@ -0,0 +1 @@ +{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file1.group": "root", "services.test.files.file1.mode": "0644", "services.test.files.file1.name": "/tmp/file1", "services.test.files.file1.owner": "root", "services.test.files.file1.source": "file1", "services.test.files.file1.templating": true, "services.test.files.file1.activate": true} diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/__init__.py b/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py b/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py new file mode 100644 index 00000000..ddfdcdf9 --- /dev/null +++ b/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py @@ -0,0 +1,32 @@ +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="condition", doc="No change", default="non", properties=frozenset({"mandatory", "normal"})) +option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))})) +option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))})) +option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_10 = StrOption(name="group", doc="group", default="root") +option_11 = StrOption(name="mode", doc="mode", default="0644") +option_12 = StrOption(name="name", doc="name", default="/tmp/file1") +option_13 = StrOption(name="owner", doc="owner", default="root") +option_14 = StrOption(name="source", doc="source", default="file1") +option_15 = BoolOption(name="templating", doc="templating", default=True) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")}))) +option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) +option_8 = OptionDescription(name="files", doc="files", children=[option_9]) +option_7 = OptionDescription(name="test", doc="test", children=[option_8]) +option_7.impl_set_information('manage', True) +option_6 = OptionDescription(name="services", doc="services", children=[option_7], properties=frozenset({"hidden"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_6]) diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/00-base.xml b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/00-base.xml new file mode 100644 index 00000000..fa344e7a --- /dev/null +++ b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/00-base.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + oui + + + + + + + + + oui + maybe + mode_conteneur_actif + mode_conteneur_actif2 + afilllist + + + + diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/__init__.py b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/makedict/base.json b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/makedict/base.json new file mode 100644 index 00000000..111c3669 --- /dev/null +++ b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/makedict/base.json @@ -0,0 +1 @@ +{"rougail.general.condition": "oui", "services.test.files.file1.group": "root", "services.test.files.file1.mode": "0644", "services.test.files.file1.name": "/tmp/file1", "services.test.files.file1.owner": "root", "services.test.files.file1.source": "file1", "services.test.files.file1.templating": true, "services.test.files.file1.activate": false} diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/__init__.py b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py new file mode 100644 index 00000000..72dd21fa --- /dev/null +++ b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py @@ -0,0 +1,32 @@ +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="condition", doc="No change", default="oui", properties=frozenset({"mandatory", "normal"})) +option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))})) +option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui')})), Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('maybe')}))})) +option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_10 = StrOption(name="group", doc="group", default="root") +option_11 = StrOption(name="mode", doc="mode", default="0644") +option_12 = StrOption(name="name", doc="name", default="/tmp/file1") +option_13 = StrOption(name="owner", doc="owner", default="root") +option_14 = StrOption(name="source", doc="source", default="file1") +option_15 = BoolOption(name="templating", doc="templating", default=True) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")}))) +option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) +option_8 = OptionDescription(name="files", doc="files", children=[option_9]) +option_7 = OptionDescription(name="test", doc="test", children=[option_8]) +option_7.impl_set_information('manage', True) +option_6 = OptionDescription(name="services", doc="services", children=[option_7], properties=frozenset({"hidden"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_6]) diff --git a/tests/dictionaries/10load_disabled_if_not_in_fallback_force/00-base.xml b/tests/dictionaries/10load_disabled_if_not_in_fallback_force/00-base.xml index 21c31773..19e5a39b 100644 --- a/tests/dictionaries/10load_disabled_if_not_in_fallback_force/00-base.xml +++ b/tests/dictionaries/10load_disabled_if_not_in_fallback_force/00-base.xml @@ -15,7 +15,7 @@ - + oui mode_conteneur_actif mode_conteneur_actif2 diff --git a/tests/dictionaries/10load_disabled_if_not_in_fallback_force/tiramisu/base.py b/tests/dictionaries/10load_disabled_if_not_in_fallback_force/tiramisu/base.py index 3b9eb2fc..9641b213 100644 --- a/tests/dictionaries/10load_disabled_if_not_in_fallback_force/tiramisu/base.py +++ b/tests/dictionaries/10load_disabled_if_not_in_fallback_force/tiramisu/base.py @@ -13,8 +13,8 @@ except: from tiramisu import * from rougail.tiramisu import ConvertDynOptionDescription option_3 = StrOption(name="condition", doc="No change", default="non", properties=frozenset({"mandatory", "normal"})) -option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))})) -option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"mandatory", "normal", Calculation(calc_value, Params(ParamValue('disabled'), kwargs={'condition': ParamOption(option_3, todict=True), 'expected': ParamValue('oui'), 'reverse_condition': ParamValue(True)}))})) +option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"disabled", "mandatory", "normal"})) +option_5 = StrOption(name="mode_conteneur_actif2", doc="No change", default="non", properties=frozenset({"disabled", "mandatory", "normal"})) option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4, option_5], properties=frozenset({"normal"})) option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py b/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py index fbe6962d..4fa49b3d 100644 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py +++ b/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5), 'expected_1': ParamValue("oui")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5), 'expected_1': ParamValue("oui"), 'condition_operator': ParamValue("OR")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/80hidden_if_in_filelist/00-base.xml b/tests/dictionaries/80hidden_if_in_filelist/00-base.xml index 6785d019..1b452337 100644 --- a/tests/dictionaries/80hidden_if_in_filelist/00-base.xml +++ b/tests/dictionaries/80hidden_if_in_filelist/00-base.xml @@ -1,12 +1,10 @@ - - - non