diff --git a/src/rougail/data/rougail.dtd b/src/rougail/data/rougail.dtd index 61f2ba6f0..efb7edb63 100644 --- a/src/rougail/data/rougail.dtd +++ b/src/rougail/data/rougail.dtd @@ -69,7 +69,9 @@ + + diff --git a/src/rougail/template/base.py b/src/rougail/template/base.py index aaef46dfb..aa324cb12 100644 --- a/src/rougail/template/base.py +++ b/src/rougail/template/base.py @@ -55,9 +55,12 @@ log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) -INFORMATIONS = {'files': ['source', 'mode', 'owner', 'group', 'engine', 'included'], +INFORMATIONS = {'files': ['source', 'mode', 'engine', 'included'], 'overrides': ['name', 'source', 'engine'], } +DEFAULT = {'files': ['owner', 'group'], + 'overrides': [], + } class RougailLeaderIndex: @@ -196,7 +199,10 @@ class RougailExtra: return self._suboption.items() def __str__(self): - return f'' + suboptions = {} + for key, value in self._suboption.items(): + suboptions[key] = str(value) + return f'' class RougailBaseTemplate: @@ -377,6 +383,7 @@ class RougailBaseTemplate: type_ = await fills.option.name() for fill_obj in await fills.list('all'): fill = await fill_obj.value.dict() + self.get_default(type_, fill, fill_obj) await self.get_informations(type_, fill, fill_obj) if 'included' in fill: if (fill['included'] == 'no' and included is True) or \ @@ -407,6 +414,19 @@ class RougailBaseTemplate: if ori_dir is not None: chdir(ori_dir) + def get_default(self, + type_: str, + dico: dict, + obj: 'Option', + ) -> None: + for key in DEFAULT.get(type_, []): + default_key = f'default_{type_}_{key}' + if default_key in RougailConfig: + default_value = RougailConfig[default_key] + else: + default_value = undefined + dico[key] = dico.get(key, default_value) + async def get_informations(self, type_: str, dico: dict, @@ -516,6 +536,10 @@ class RougailBaseTemplate: value = await option.value.get() variables[await option.option.name()] = value if isinstance(is_service_namespace, str) and is_service_namespace + 's' in INFORMATIONS: + self.get_default(is_service_namespace + 's', + variables, + optiondescription, + ) await self.get_informations(is_service_namespace + 's', variables, optiondescription, diff --git a/tests/dictionaries/01base_file_owner/00-base.xml b/tests/dictionaries/01base_file_owner/00-base.xml new file mode 100644 index 000000000..2c622d2a4 --- /dev/null +++ b/tests/dictionaries/01base_file_owner/00-base.xml @@ -0,0 +1,16 @@ + + + + + /etc/file + /etc/file2 + + + + + + non + + + + diff --git a/tests/dictionaries/01base_file_owner/__init__.py b/tests/dictionaries/01base_file_owner/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dictionaries/01base_file_owner/makedict/after.json b/tests/dictionaries/01base_file_owner/makedict/after.json new file mode 100644 index 000000000..60a3f954d --- /dev/null +++ b/tests/dictionaries/01base_file_owner/makedict/after.json @@ -0,0 +1,46 @@ +{ + "rougail.general.mode_conteneur_actif": { + "owner": "default", + "value": "non" + }, + "services.test.files.file.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.name": { + "owner": "default", + "value": "/etc/file" + }, + "services.test.files.file.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.activate": { + "owner": "default", + "value": true + }, + "services.test.files.file2.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.name": { + "owner": "default", + "value": "/etc/file2" + }, + "services.test.files.file2.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.activate": { + "owner": "default", + "value": true + }, + "services.test.activate": { + "owner": "default", + "value": true + }, + "services.test.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/01base_file_owner/makedict/base.json b/tests/dictionaries/01base_file_owner/makedict/base.json new file mode 100644 index 000000000..870ca4270 --- /dev/null +++ b/tests/dictionaries/01base_file_owner/makedict/base.json @@ -0,0 +1,13 @@ +{ + "rougail.general.mode_conteneur_actif": "non", + "services.test.files.file.group": "nobody", + "services.test.files.file.name": "/etc/file", + "services.test.files.file.owner": "nobody", + "services.test.files.file.activate": true, + "services.test.files.file2.group": "nobody", + "services.test.files.file2.name": "/etc/file2", + "services.test.files.file2.owner": "nobody", + "services.test.files.file2.activate": true, + "services.test.activate": true, + "services.test.manage": true +} diff --git a/tests/dictionaries/01base_file_owner/makedict/before.json b/tests/dictionaries/01base_file_owner/makedict/before.json new file mode 100644 index 000000000..60a3f954d --- /dev/null +++ b/tests/dictionaries/01base_file_owner/makedict/before.json @@ -0,0 +1,46 @@ +{ + "rougail.general.mode_conteneur_actif": { + "owner": "default", + "value": "non" + }, + "services.test.files.file.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.name": { + "owner": "default", + "value": "/etc/file" + }, + "services.test.files.file.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.activate": { + "owner": "default", + "value": true + }, + "services.test.files.file2.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.name": { + "owner": "default", + "value": "/etc/file2" + }, + "services.test.files.file2.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.activate": { + "owner": "default", + "value": true + }, + "services.test.activate": { + "owner": "default", + "value": true + }, + "services.test.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/01base_file_owner/result/etc/file b/tests/dictionaries/01base_file_owner/result/etc/file new file mode 100644 index 000000000..4089fbcce --- /dev/null +++ b/tests/dictionaries/01base_file_owner/result/etc/file @@ -0,0 +1,2 @@ +non +non diff --git a/tests/dictionaries/01base_file_owner/result/etc/file2 b/tests/dictionaries/01base_file_owner/result/etc/file2 new file mode 100644 index 000000000..4089fbcce --- /dev/null +++ b/tests/dictionaries/01base_file_owner/result/etc/file2 @@ -0,0 +1,2 @@ +non +non diff --git a/tests/dictionaries/01base_file_owner/result/tmpfiles.d/0rougail.conf b/tests/dictionaries/01base_file_owner/result/tmpfiles.d/0rougail.conf new file mode 100644 index 000000000..1cb93ff06 --- /dev/null +++ b/tests/dictionaries/01base_file_owner/result/tmpfiles.d/0rougail.conf @@ -0,0 +1,2 @@ +C /etc/file 0644 nobody nobody - /usr/local/lib/etc/file +C /etc/file2 0644 nobody nobody - /usr/local/lib/etc/file2 diff --git a/tests/dictionaries/01base_file_owner/tiramisu/base.py b/tests/dictionaries/01base_file_owner/tiramisu/base.py new file mode 100644 index 000000000..a321c2ad6 --- /dev/null +++ b/tests/dictionaries/01base_file_owner/tiramisu/base.py @@ -0,0 +1,38 @@ +from importlib.machinery import SourceFileLoader as _SourceFileLoader +from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec +class func: + pass +_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 function in dir(_func): + if function.startswith('_'): + continue + setattr(func, function, getattr(_func, function)) +try: + from tiramisu3 import * +except: + from tiramisu import * +option_3 = StrOption(name="mode_conteneur_actif", doc="Description", default="non", properties=frozenset({"mandatory", "normal"})) +option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_8 = UsernameOption(name="group", doc="group", default="nobody") +option_9 = FilenameOption(name="name", doc="name", default="/etc/file") +option_10 = UsernameOption(name="owner", doc="owner", default="nobody") +option_11 = BoolOption(name="activate", doc="activate", default=True) +option_7 = OptionDescription(name="file", doc="file", children=[option_8, option_9, option_10, option_11]) +option_7.impl_set_information('source', "file") +option_13 = UsernameOption(name="group", doc="group", default="nobody") +option_14 = FilenameOption(name="name", doc="name", default="/etc/file2") +option_15 = UsernameOption(name="owner", doc="owner", default="nobody") +option_16 = BoolOption(name="activate", doc="activate", default=True) +option_12 = OptionDescription(name="file2", doc="file2", children=[option_13, option_14, option_15, option_16]) +option_12.impl_set_information('engine', "jinja2") +option_12.impl_set_information('source', "file2") +option_6 = OptionDescription(name="files", doc="files", children=[option_7, option_12]) +option_17 = BoolOption(name="activate", doc="activate", default=True) +option_18 = BoolOption(name="manage", doc="manage", default=True) +option_5 = OptionDescription(name="test", doc="test", children=[option_6, option_17, option_18]) +option_4 = OptionDescription(name="services", doc="services", children=[option_5], properties=frozenset({"hidden"})) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_4]) diff --git a/tests/dictionaries/01base_file_owner/tmpl/file b/tests/dictionaries/01base_file_owner/tmpl/file new file mode 100644 index 000000000..27ff6834c --- /dev/null +++ b/tests/dictionaries/01base_file_owner/tmpl/file @@ -0,0 +1,2 @@ +%%mode_conteneur_actif +%%rougail.general.mode_conteneur_actif diff --git a/tests/dictionaries/01base_file_owner/tmpl/file2 b/tests/dictionaries/01base_file_owner/tmpl/file2 new file mode 100644 index 000000000..6d214113d --- /dev/null +++ b/tests/dictionaries/01base_file_owner/tmpl/file2 @@ -0,0 +1,2 @@ +{{ mode_conteneur_actif }} +{{ rougail.general.mode_conteneur_actif }} diff --git a/tests/dictionaries/01base_file_owner_variable/00-base.xml b/tests/dictionaries/01base_file_owner_variable/00-base.xml new file mode 100644 index 000000000..78a211db4 --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/00-base.xml @@ -0,0 +1,22 @@ + + + + + /etc/file + /etc/file2 + + + + + + non + + + nobody + + + nobody + + + + diff --git a/tests/dictionaries/01base_file_owner_variable/__init__.py b/tests/dictionaries/01base_file_owner_variable/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/dictionaries/01base_file_owner_variable/makedict/after.json b/tests/dictionaries/01base_file_owner_variable/makedict/after.json new file mode 100644 index 000000000..99889bce8 --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/makedict/after.json @@ -0,0 +1,54 @@ +{ + "rougail.general.mode_conteneur_actif": { + "owner": "default", + "value": "non" + }, + "rougail.general.owner": { + "owner": "default", + "value": "nobody" + }, + "rougail.general.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.name": { + "owner": "default", + "value": "/etc/file" + }, + "services.test.files.file.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.activate": { + "owner": "default", + "value": true + }, + "services.test.files.file2.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.name": { + "owner": "default", + "value": "/etc/file2" + }, + "services.test.files.file2.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.activate": { + "owner": "default", + "value": true + }, + "services.test.activate": { + "owner": "default", + "value": true + }, + "services.test.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/01base_file_owner_variable/makedict/base.json b/tests/dictionaries/01base_file_owner_variable/makedict/base.json new file mode 100644 index 000000000..b586a77ce --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/makedict/base.json @@ -0,0 +1,15 @@ +{ + "rougail.general.mode_conteneur_actif": "non", + "rougail.general.owner": "nobody", + "rougail.general.group": "nobody", + "services.test.files.file.group": "nobody", + "services.test.files.file.name": "/etc/file", + "services.test.files.file.owner": "nobody", + "services.test.files.file.activate": true, + "services.test.files.file2.group": "nobody", + "services.test.files.file2.name": "/etc/file2", + "services.test.files.file2.owner": "nobody", + "services.test.files.file2.activate": true, + "services.test.activate": true, + "services.test.manage": true +} diff --git a/tests/dictionaries/01base_file_owner_variable/makedict/before.json b/tests/dictionaries/01base_file_owner_variable/makedict/before.json new file mode 100644 index 000000000..99889bce8 --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/makedict/before.json @@ -0,0 +1,54 @@ +{ + "rougail.general.mode_conteneur_actif": { + "owner": "default", + "value": "non" + }, + "rougail.general.owner": { + "owner": "default", + "value": "nobody" + }, + "rougail.general.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.name": { + "owner": "default", + "value": "/etc/file" + }, + "services.test.files.file.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file.activate": { + "owner": "default", + "value": true + }, + "services.test.files.file2.group": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.name": { + "owner": "default", + "value": "/etc/file2" + }, + "services.test.files.file2.owner": { + "owner": "default", + "value": "nobody" + }, + "services.test.files.file2.activate": { + "owner": "default", + "value": true + }, + "services.test.activate": { + "owner": "default", + "value": true + }, + "services.test.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/01base_file_owner_variable/result/etc/file b/tests/dictionaries/01base_file_owner_variable/result/etc/file new file mode 100644 index 000000000..4089fbcce --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/result/etc/file @@ -0,0 +1,2 @@ +non +non diff --git a/tests/dictionaries/01base_file_owner_variable/result/etc/file2 b/tests/dictionaries/01base_file_owner_variable/result/etc/file2 new file mode 100644 index 000000000..4089fbcce --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/result/etc/file2 @@ -0,0 +1,2 @@ +non +non diff --git a/tests/dictionaries/01base_file_owner_variable/result/tmpfiles.d/0rougail.conf b/tests/dictionaries/01base_file_owner_variable/result/tmpfiles.d/0rougail.conf new file mode 100644 index 000000000..1cb93ff06 --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/result/tmpfiles.d/0rougail.conf @@ -0,0 +1,2 @@ +C /etc/file 0644 nobody nobody - /usr/local/lib/etc/file +C /etc/file2 0644 nobody nobody - /usr/local/lib/etc/file2 diff --git a/tests/dictionaries/01base_file_owner_variable/tiramisu/base.py b/tests/dictionaries/01base_file_owner_variable/tiramisu/base.py new file mode 100644 index 000000000..b1ba60bd3 --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/tiramisu/base.py @@ -0,0 +1,40 @@ +from importlib.machinery import SourceFileLoader as _SourceFileLoader +from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec +class func: + pass +_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 function in dir(_func): + if function.startswith('_'): + continue + setattr(func, function, getattr(_func, function)) +try: + from tiramisu3 import * +except: + from tiramisu import * +option_3 = StrOption(name="mode_conteneur_actif", doc="Description", default="non", properties=frozenset({"mandatory", "normal"})) +option_4 = UsernameOption(name="owner", doc="owner", default="nobody", properties=frozenset({"mandatory", "normal"})) +option_5 = UsernameOption(name="group", doc="group", default="nobody", properties=frozenset({"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_10 = SymLinkOption(name="group", opt=option_5) +option_11 = FilenameOption(name="name", doc="name", default="/etc/file") +option_12 = SymLinkOption(name="owner", opt=option_4) +option_13 = BoolOption(name="activate", doc="activate", default=True) +option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13]) +option_9.impl_set_information('source', "file") +option_15 = SymLinkOption(name="group", opt=option_5) +option_16 = FilenameOption(name="name", doc="name", default="/etc/file2") +option_17 = SymLinkOption(name="owner", opt=option_4) +option_18 = BoolOption(name="activate", doc="activate", default=True) +option_14 = OptionDescription(name="file2", doc="file2", children=[option_15, option_16, option_17, option_18]) +option_14.impl_set_information('engine', "jinja2") +option_14.impl_set_information('source', "file2") +option_8 = OptionDescription(name="files", doc="files", children=[option_9, option_14]) +option_19 = BoolOption(name="activate", doc="activate", default=True) +option_20 = BoolOption(name="manage", doc="manage", default=True) +option_7 = OptionDescription(name="test", doc="test", children=[option_8, option_19, option_20]) +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/01base_file_owner_variable/tmpl/file b/tests/dictionaries/01base_file_owner_variable/tmpl/file new file mode 100644 index 000000000..27ff6834c --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/tmpl/file @@ -0,0 +1,2 @@ +%%mode_conteneur_actif +%%rougail.general.mode_conteneur_actif diff --git a/tests/dictionaries/01base_file_owner_variable/tmpl/file2 b/tests/dictionaries/01base_file_owner_variable/tmpl/file2 new file mode 100644 index 000000000..6d214113d --- /dev/null +++ b/tests/dictionaries/01base_file_owner_variable/tmpl/file2 @@ -0,0 +1,2 @@ +{{ mode_conteneur_actif }} +{{ rougail.general.mode_conteneur_actif }}