From f9acc7d6f8cfbc69703c820fafd2805e93c509d9 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 23 Nov 2021 08:51:03 +0100 Subject: [PATCH] better leader support in extra --- src/rougail/template/base.py | 2 +- src/rougail/template/engine/creole.py | 2 +- .../60extra_leadership/extra_dirs/extra/00-base.xml | 2 +- .../60extra_leadership/makedict/after.json | 4 ++-- .../60extra_leadership/makedict/base.json | 6 +++--- .../60extra_leadership/makedict/before.json | 4 ++-- .../dictionaries/60extra_leadership/tiramisu/base.py | 2 +- tests/dictionaries/60extra_leadership/tmpl/mailname | 12 ++++++------ tests/dictionaries/60extra_leadership/tmpl/mailname2 | 12 ++++++------ .../60extra_leadership_name/tmpl/mailname | 12 ++++++------ .../60extra_leadership_name/tmpl/mailname2 | 12 ++++++------ .../60extra_leadership_name_item/tmpl/mailname | 12 ++++++------ .../60extra_leadership_name_item/tmpl/mailname2 | 12 ++++++------ .../60extra_leadership_valid_enum/tmpl/mailname | 12 ++++++------ .../60extra_leadership_valid_enum/tmpl/mailname2 | 12 ++++++------ 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/rougail/template/base.py b/src/rougail/template/base.py index 5c0b50c45..1a68d8921 100644 --- a/src/rougail/template/base.py +++ b/src/rougail/template/base.py @@ -448,7 +448,7 @@ class RougailBaseTemplate: await suboption.option.name(), await suboption.option.path(), ) - variables[leadership_name] = leader + variables[leadership_name] = RougailExtra({leader_name: leader}) else: if is_service_namespace == 'root': new_is_service_namespace = 'service_name' diff --git a/src/rougail/template/engine/creole.py b/src/rougail/template/engine/creole.py index 631283d16..c63088f96 100644 --- a/src/rougail/template/engine/creole.py +++ b/src/rougail/template/engine/creole.py @@ -118,7 +118,7 @@ def process(filename: str, ) data = str(cheetah_template) except NotFound as err: # pragma: no cover - varname = err.args[0][13:-1] + varname = err.args[0][13:].split(' ', 1)[0][:-1] if filename: msg = f"Error: unknown variable used in template {filename} to {destfilename}: {varname}" else: diff --git a/tests/dictionaries/60extra_leadership/extra_dirs/extra/00-base.xml b/tests/dictionaries/60extra_leadership/extra_dirs/extra/00-base.xml index ee7f931f6..7ffc25da5 100644 --- a/tests/dictionaries/60extra_leadership/extra_dirs/extra/00-base.xml +++ b/tests/dictionaries/60extra_leadership/extra_dirs/extra/00-base.xml @@ -2,7 +2,7 @@ - + test diff --git a/tests/dictionaries/60extra_leadership/makedict/after.json b/tests/dictionaries/60extra_leadership/makedict/after.json index 0295b3e42..7a0fe4a1e 100644 --- a/tests/dictionaries/60extra_leadership/makedict/after.json +++ b/tests/dictionaries/60extra_leadership/makedict/after.json @@ -7,13 +7,13 @@ "owner": "default", "value": "non" }, - "extra.ejabberd.description.description": { + "extra.ejabberd.leadership.description": { "owner": "default", "value": [ "test" ] }, - "extra.ejabberd.description.mode": { + "extra.ejabberd.leadership.mode": { "owner": [ "default" ], diff --git a/tests/dictionaries/60extra_leadership/makedict/base.json b/tests/dictionaries/60extra_leadership/makedict/base.json index b67b1029d..bbab96af1 100644 --- a/tests/dictionaries/60extra_leadership/makedict/base.json +++ b/tests/dictionaries/60extra_leadership/makedict/base.json @@ -1,10 +1,10 @@ { "rougail.general.mode_conteneur_actif": "non", "rougail.general.activer_ejabberd": "non", - "extra.ejabberd.description.description": [ + "extra.ejabberd.leadership.description": [ { - "extra.ejabberd.description.description": "test", - "extra.ejabberd.description.mode": "pre" + "extra.ejabberd.leadership.description": "test", + "extra.ejabberd.leadership.mode": "pre" } ], "services.test.files.mailname.name": "/etc/mailname", diff --git a/tests/dictionaries/60extra_leadership/makedict/before.json b/tests/dictionaries/60extra_leadership/makedict/before.json index 0295b3e42..7a0fe4a1e 100644 --- a/tests/dictionaries/60extra_leadership/makedict/before.json +++ b/tests/dictionaries/60extra_leadership/makedict/before.json @@ -7,13 +7,13 @@ "owner": "default", "value": "non" }, - "extra.ejabberd.description.description": { + "extra.ejabberd.leadership.description": { "owner": "default", "value": [ "test" ] }, - "extra.ejabberd.description.mode": { + "extra.ejabberd.leadership.mode": { "owner": [ "default" ], diff --git a/tests/dictionaries/60extra_leadership/tiramisu/base.py b/tests/dictionaries/60extra_leadership/tiramisu/base.py index b306fe56a..3a014bb60 100644 --- a/tests/dictionaries/60extra_leadership/tiramisu/base.py +++ b/tests/dictionaries/60extra_leadership/tiramisu/base.py @@ -17,7 +17,7 @@ option_2 = OptionDescription(name="general", doc="général", children=[option_3 option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) option_8 = StrOption(name="description", doc="description", multi=True, default=['test'], properties=frozenset({"mandatory"})) option_9 = StrOption(name="mode", doc="mode", multi=True, default_multi="pre", properties=frozenset({"mandatory", "normal"})) -option_7 = Leadership(name="description", doc="description", children=[option_8, option_9], properties=frozenset({"normal"})) +option_7 = Leadership(name="leadership", doc="description", children=[option_8, option_9], properties=frozenset({"normal"})) option_6 = OptionDescription(name="ejabberd", doc="ejabberd", children=[option_7], properties=frozenset({"normal"})) option_5 = OptionDescription(name="extra", doc="extra", children=[option_6]) option_14 = FilenameOption(name="name", doc="name", default="/etc/mailname") diff --git a/tests/dictionaries/60extra_leadership/tmpl/mailname b/tests/dictionaries/60extra_leadership/tmpl/mailname index de1500e6c..c98064496 100644 --- a/tests/dictionaries/60extra_leadership/tmpl/mailname +++ b/tests/dictionaries/60extra_leadership/tmpl/mailname @@ -1,11 +1,11 @@ -%if 'test' in %%extra.ejabberd.description +%if 'test' in %%extra.ejabberd.leadership.description contain test %end if -%%len(%%extra.ejabberd.description) -%if 'a' in %%extra.ejabberd.description +%%len(%%extra.ejabberd.leadership.description) +%if 'a' in %%extra.ejabberd.leadership.description contain a %end if -%for %%description in %%extra.ejabberd.description +%for %%description in %%extra.ejabberd.leadership.description leader: %%description follower: %%description.mode %if %%description <= %%description.mode @@ -31,5 +31,5 @@ diff %set %%var = %%description.mode + %%description %%var %end for -leader2: %%extra.ejabberd.description[0] -follower2: %%extra.ejabberd.description[0].mode +leader2: %%extra.ejabberd.leadership.description[0] +follower2: %%extra.ejabberd.leadership.description[0].mode diff --git a/tests/dictionaries/60extra_leadership/tmpl/mailname2 b/tests/dictionaries/60extra_leadership/tmpl/mailname2 index 589c548e7..fd6190b4b 100644 --- a/tests/dictionaries/60extra_leadership/tmpl/mailname2 +++ b/tests/dictionaries/60extra_leadership/tmpl/mailname2 @@ -1,11 +1,11 @@ -{% if 'test' in extra.ejabberd.description -%} +{% if 'test' in extra.ejabberd.leadership.description -%} contain test {% endif -%} -{{ extra.ejabberd.description|length }} -{% if 'a' in extra.ejabberd.description -%} +{{ extra.ejabberd.leadership.description|length }} +{% if 'a' in extra.ejabberd.leadership.description -%} contain a {% endif -%} -{% for description in extra.ejabberd.description -%} +{% for description in extra.ejabberd.leadership.description -%} leader: {{ description }} follower: {{ description.mode }} {% if description <= description.mode -%} @@ -29,5 +29,5 @@ diff {{ description + description.mode }} {{ description.mode + description }} {% endfor -%} -leader2: {{ extra.ejabberd.description[0] }} -follower2: {{ extra.ejabberd.description[0].mode }} +leader2: {{ extra.ejabberd.leadership.description[0] }} +follower2: {{ extra.ejabberd.leadership.description[0].mode }} diff --git a/tests/dictionaries/60extra_leadership_name/tmpl/mailname b/tests/dictionaries/60extra_leadership_name/tmpl/mailname index 23cbe10eb..92eeafc40 100644 --- a/tests/dictionaries/60extra_leadership_name/tmpl/mailname +++ b/tests/dictionaries/60extra_leadership_name/tmpl/mailname @@ -1,11 +1,11 @@ -%if 'test' in %%extra.ejabberd.new_name +%if 'test' in %%extra.ejabberd.new_name.description contain test %end if -%%len(%%extra.ejabberd.new_name) -%if 'a' in %%extra.ejabberd.new_name +%%len(%%extra.ejabberd.new_name.description) +%if 'a' in %%extra.ejabberd.new_name.description contain a %end if -%for %%description in %%extra.ejabberd.new_name +%for %%description in %%extra.ejabberd.new_name.description leader: %%description follower: %%description.mode %if %%description <= %%description.mode @@ -31,5 +31,5 @@ diff %set %%var = %%description.mode + %%description %%var %end for -leader2: %%extra.ejabberd.new_name[0].description -follower2: %%extra.ejabberd.new_name[0].mode +leader2: %%extra.ejabberd.new_name.description[0].description +follower2: %%extra.ejabberd.new_name.description[0].mode diff --git a/tests/dictionaries/60extra_leadership_name/tmpl/mailname2 b/tests/dictionaries/60extra_leadership_name/tmpl/mailname2 index 4860700df..0823099e8 100644 --- a/tests/dictionaries/60extra_leadership_name/tmpl/mailname2 +++ b/tests/dictionaries/60extra_leadership_name/tmpl/mailname2 @@ -1,11 +1,11 @@ -{% if 'test' in extra.ejabberd.new_name -%} +{% if 'test' in extra.ejabberd.new_name.description -%} contain test {% endif -%} -{{ extra.ejabberd.new_name |length }} -{% if 'a' in extra.ejabberd.new_name -%} +{{ extra.ejabberd.new_name.description |length }} +{% if 'a' in extra.ejabberd.new_name.description -%} contain a {% endif -%} -{% for description in extra.ejabberd.new_name -%} +{% for description in extra.ejabberd.new_name.description -%} leader: {{ description }} follower: {{ description.mode }} {% if description <= description.mode -%} @@ -29,5 +29,5 @@ diff {{ description + description.mode }} {{ description.mode + description }} {% endfor -%} -leader2: {{ extra.ejabberd.new_name[0].description }} -follower2: {{ extra.ejabberd.new_name[0].mode }} +leader2: {{ extra.ejabberd.new_name.description[0].description }} +follower2: {{ extra.ejabberd.new_name.description[0].mode }} diff --git a/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname b/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname index 4f68721d8..df72e5964 100644 --- a/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname +++ b/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname @@ -1,11 +1,11 @@ -%if 'test' in %%extra['ejabberd']['new_name'] +%if 'test' in %%extra['ejabberd']['new_name']['description'] contain test %end if -%%len(%%extra['ejabberd']['new_name']) -%if 'a' in %%extra['ejabberd']['new_name'] +%%len(%%extra['ejabberd']['new_name']['description']) +%if 'a' in %%extra['ejabberd']['new_name']['description'] contain a %end if -%for %%description in %%extra['ejabberd']['new_name'] +%for %%description in %%extra['ejabberd']['new_name']['description'] leader: %%description follower: %%description['mode'] %if %%description <= %%description['mode'] @@ -31,5 +31,5 @@ diff %set %%var = %%description['mode'] + %%description %%var %end for -leader2: %%extra['ejabberd']['new_name'][0]['description'] -follower2: %%extra['ejabberd']['new_name'][0]['mode'] +leader2: %%extra['ejabberd']['new_name']['description'][0] +follower2: %%extra['ejabberd']['new_name']['description'][0]['mode'] diff --git a/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname2 b/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname2 index 4860700df..78ee2b6ea 100644 --- a/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname2 +++ b/tests/dictionaries/60extra_leadership_name_item/tmpl/mailname2 @@ -1,11 +1,11 @@ -{% if 'test' in extra.ejabberd.new_name -%} +{% if 'test' in extra.ejabberd.new_name.description -%} contain test {% endif -%} -{{ extra.ejabberd.new_name |length }} -{% if 'a' in extra.ejabberd.new_name -%} +{{ extra.ejabberd.new_name.description |length }} +{% if 'a' in extra.ejabberd.new_name.description -%} contain a {% endif -%} -{% for description in extra.ejabberd.new_name -%} +{% for description in extra.ejabberd.new_name.description -%} leader: {{ description }} follower: {{ description.mode }} {% if description <= description.mode -%} @@ -29,5 +29,5 @@ diff {{ description + description.mode }} {{ description.mode + description }} {% endfor -%} -leader2: {{ extra.ejabberd.new_name[0].description }} -follower2: {{ extra.ejabberd.new_name[0].mode }} +leader2: {{ extra.ejabberd.new_name.description[0] }} +follower2: {{ extra.ejabberd.new_name.description[0].mode }} diff --git a/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname b/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname index de1500e6c..56abb7a07 100644 --- a/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname +++ b/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname @@ -1,11 +1,11 @@ -%if 'test' in %%extra.ejabberd.description +%if 'test' in %%extra.ejabberd.description.description contain test %end if -%%len(%%extra.ejabberd.description) -%if 'a' in %%extra.ejabberd.description +%%len(%%extra.ejabberd.description.description) +%if 'a' in %%extra.ejabberd.description.description contain a %end if -%for %%description in %%extra.ejabberd.description +%for %%description in %%extra.ejabberd.description.description leader: %%description follower: %%description.mode %if %%description <= %%description.mode @@ -31,5 +31,5 @@ diff %set %%var = %%description.mode + %%description %%var %end for -leader2: %%extra.ejabberd.description[0] -follower2: %%extra.ejabberd.description[0].mode +leader2: %%extra.ejabberd.description.description[0] +follower2: %%extra.ejabberd.description.description[0].mode diff --git a/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname2 b/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname2 index 589c548e7..99fc5bab6 100644 --- a/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname2 +++ b/tests/dictionaries/60extra_leadership_valid_enum/tmpl/mailname2 @@ -1,11 +1,11 @@ -{% if 'test' in extra.ejabberd.description -%} +{% if 'test' in extra.ejabberd.description.description -%} contain test {% endif -%} -{{ extra.ejabberd.description|length }} -{% if 'a' in extra.ejabberd.description -%} +{{ extra.ejabberd.description.description|length }} +{% if 'a' in extra.ejabberd.description.description -%} contain a {% endif -%} -{% for description in extra.ejabberd.description -%} +{% for description in extra.ejabberd.description.description -%} leader: {{ description }} follower: {{ description.mode }} {% if description <= description.mode -%} @@ -29,5 +29,5 @@ diff {{ description + description.mode }} {{ description.mode + description }} {% endfor -%} -leader2: {{ extra.ejabberd.description[0] }} -follower2: {{ extra.ejabberd.description[0].mode }} +leader2: {{ extra.ejabberd.description.description[0] }} +follower2: {{ extra.ejabberd.description.description[0].mode }}