From 7191bbbcb3094b02f19b06c1a75b058cf858694b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 9 Jul 2020 18:48:51 +0200 Subject: [PATCH] add default value to True in boolean --- src/rougail/loader.py | 11 ++++------- .../11disabled_if_in_filelist/00-base.xml | 4 +--- .../11disabled_if_in_filelist/makedict/base.json | 2 +- .../11disabled_if_in_filelist/result/00-base.xml | 6 +----- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/rougail/loader.py b/src/rougail/loader.py index d24732ea..bff28aeb 100644 --- a/src/rougail/loader.py +++ b/src/rougail/loader.py @@ -60,7 +60,7 @@ CONVERT_OPTION = {'number': dict(opttype=IntOption), 'string': dict(opttype=StrOption), 'password': dict(opttype=PasswordOption), 'mail': dict(opttype=EmailOption), - 'boolean': dict(opttype=BoolOption), + 'boolean': dict(opttype=BoolOption, initkwargs={'default': True}), 'symlink': dict(opttype=SymLinkOption), 'filename': dict(opttype=FilenameOption), 'date': dict(opttype=DateOption), @@ -269,6 +269,9 @@ class Variable(Common): self.option = None self.informations = {} self.attrib = {} + convert_option = CONVERT_OPTION[elt.attrib['type']] + if 'initkwargs' in convert_option: + self.attrib.update(convert_option['initkwargs']) if elt.attrib['type'] != 'symlink': self.attrib['properties'] = [] self.attrib['validators'] = [] @@ -278,15 +281,12 @@ class Variable(Common): self.populate_attrib(elt) self.is_follower = is_follower self.is_leader = is_leader - convert_option = CONVERT_OPTION[elt.attrib['type']] self.object_type = convert_option['opttype'] self.populate_choice(elt) for child in elt: self.populate_property(child) self.populate_value(child) self.populate_check(child) - if 'initkwargs' in convert_option: - self.attrib.update(convert_option['initkwargs']) if elt.attrib['type'] == 'symlink': self.attrib['opt'] = storage.get(self.attrib['opt']) @@ -371,9 +371,6 @@ class Variable(Common): if not self.is_leader: self.attrib['default_multi'].append(value) else: - if 'default' in self.attrib: - raise CreoleLoaderError(_('default value already set for {}' - '').format(self.attrib['path'])) value = convert_tiramisu_value(child.text, type_) if self.is_follower: self.attrib['default_multi'] = value diff --git a/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml index 900ea4d9..6a391d6b 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist/00-base.xml @@ -15,9 +15,7 @@ non - - non - + diff --git a/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json b/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json index e6f3324a..8841e51c 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json +++ b/tests/flattener_dicos/11disabled_if_in_filelist/makedict/base.json @@ -1 +1 @@ -{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": "non", "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/etc/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": true} +{"rougail.general.condition": "non", "rougail.general.mode_conteneur_actif": "non", "rougail.general.mode_conteneur_actif2": true, "services.test.files.file.group": "root", "services.test.files.file.mode": "0644", "services.test.files.file.name": "/etc/file", "services.test.files.file.owner": "root", "services.test.files.file.source": "file", "services.test.files.file.templating": true, "services.test.files.file.activate": true} diff --git a/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml b/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml index 850de90a..5f845478 100644 --- a/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml +++ b/tests/flattener_dicos/11disabled_if_in_filelist/result/00-base.xml @@ -49,13 +49,9 @@ disabled non - - oui - non - mandatory + normal disabled - non