From 4711206c55255e7c705a61a3d748dc0eeed51f66 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 14 May 2021 07:00:55 +0200 Subject: [PATCH] allow any character as service name --- src/rougail/annotator/service.py | 12 +++++----- src/rougail/template/base.py | 2 +- .../70service_engine_dash/00-base.xml | 14 ++++++++++++ .../__init__.py | 0 .../70service_engine_dash/makedict/after.json | 14 ++++++++++++ .../70service_engine_dash/makedict/base.json | 5 +++++ .../makedict/before.json | 14 ++++++++++++ .../result/systemd/system/test-srv.service | 1 + .../result/tmpfiles.d/rougail.conf} | 0 .../70service_engine_dash/tiramisu/base.py | 22 +++++++++++++++++++ .../tmpl/test-srv.service | 1 + .../80wrong_service_name/00-base.xml | 6 ----- 12 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 tests/dictionaries/70service_engine_dash/00-base.xml rename tests/dictionaries/{80wrong_service_name => 70service_engine_dash}/__init__.py (100%) create mode 100644 tests/dictionaries/70service_engine_dash/makedict/after.json create mode 100644 tests/dictionaries/70service_engine_dash/makedict/base.json create mode 100644 tests/dictionaries/70service_engine_dash/makedict/before.json create mode 100644 tests/dictionaries/70service_engine_dash/result/systemd/system/test-srv.service rename tests/dictionaries/{80wrong_service_name/errno_76 => 70service_engine_dash/result/tmpfiles.d/rougail.conf} (100%) create mode 100644 tests/dictionaries/70service_engine_dash/tiramisu/base.py create mode 100644 tests/dictionaries/70service_engine_dash/tmpl/test-srv.service delete mode 100644 tests/dictionaries/80wrong_service_name/00-base.xml diff --git a/src/rougail/annotator/service.py b/src/rougail/annotator/service.py index 2f445a77..5b7e302e 100644 --- a/src/rougail/annotator/service.py +++ b/src/rougail/annotator/service.py @@ -28,7 +28,7 @@ from os.path import basename from typing import Tuple from rougail.i18n import _ -from rougail.utils import normalize_family, valid_variable_family_name +from rougail.utils import normalize_family from rougail.error import DictConsistencyError # a object's attribute has some annotations # that shall not be present in the exported (flatened) XML @@ -70,14 +70,14 @@ class Annotator: self.objectspace.space.services.doc = 'services' self.objectspace.space.services.path = 'services' for service_name, service in self.objectspace.space.services.service.items(): - valid_variable_family_name(service_name, service.xmlfiles) + service.name = normalize_family(service_name) activate_obj = self._generate_element('boolean', None, None, 'activate', not service.disabled, service, - '.'.join(['services', normalize_family(service_name), 'activate']), + '.'.join(['services', service.name, 'activate']), ) service.disabled = None for elttype, values in dict(vars(service)).items(): @@ -97,7 +97,7 @@ class Annotator: eltname = elttype + 's' else: eltname = elttype - path = '.'.join(['services', normalize_family(service_name), eltname]) + path = '.'.join(['services', service.name, eltname]) family = self._gen_family(eltname, path, service.xmlfiles, @@ -121,10 +121,10 @@ class Annotator: 'manage', service.manage, service, - '.'.join(['services', normalize_family(service_name), 'manage']), + '.'.join(['services', service.name, 'manage']), ) service.variable = [activate_obj, manage] - service.doc = service.name + service.doc = service_name def make_group_from_elts(self, service_name, diff --git a/src/rougail/template/base.py b/src/rougail/template/base.py index ff2e7abf..455cbbfd 100644 --- a/src/rougail/template/base.py +++ b/src/rougail/template/base.py @@ -320,7 +320,7 @@ class RougailBaseTemplate: self.prepare_template(template) for included in (True, False): for service_obj in await self.config.option('services').list('all'): - service_name = await service_obj.option.name() + service_name = await service_obj.option.description() service_type = await service_obj.information.get('type', 'service') if await service_obj.option('activate').value.get() is False: if included is False: diff --git a/tests/dictionaries/70service_engine_dash/00-base.xml b/tests/dictionaries/70service_engine_dash/00-base.xml new file mode 100644 index 00000000..6db4e912 --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/00-base.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/tests/dictionaries/80wrong_service_name/__init__.py b/tests/dictionaries/70service_engine_dash/__init__.py similarity index 100% rename from tests/dictionaries/80wrong_service_name/__init__.py rename to tests/dictionaries/70service_engine_dash/__init__.py diff --git a/tests/dictionaries/70service_engine_dash/makedict/after.json b/tests/dictionaries/70service_engine_dash/makedict/after.json new file mode 100644 index 00000000..a448d1b4 --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/makedict/after.json @@ -0,0 +1,14 @@ +{ + "rougail.general.mode_conteneur_actif": { + "owner": "default", + "value": "oui" + }, + "services.test_srv.activate": { + "owner": "default", + "value": true + }, + "services.test_srv.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/70service_engine_dash/makedict/base.json b/tests/dictionaries/70service_engine_dash/makedict/base.json new file mode 100644 index 00000000..f86cf2f8 --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/makedict/base.json @@ -0,0 +1,5 @@ +{ + "rougail.general.mode_conteneur_actif": "oui", + "services.test_srv.activate": true, + "services.test_srv.manage": true +} diff --git a/tests/dictionaries/70service_engine_dash/makedict/before.json b/tests/dictionaries/70service_engine_dash/makedict/before.json new file mode 100644 index 00000000..a448d1b4 --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/makedict/before.json @@ -0,0 +1,14 @@ +{ + "rougail.general.mode_conteneur_actif": { + "owner": "default", + "value": "oui" + }, + "services.test_srv.activate": { + "owner": "default", + "value": true + }, + "services.test_srv.manage": { + "owner": "default", + "value": true + } +} diff --git a/tests/dictionaries/70service_engine_dash/result/systemd/system/test-srv.service b/tests/dictionaries/70service_engine_dash/result/systemd/system/test-srv.service new file mode 100644 index 00000000..bd51bf63 --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/result/systemd/system/test-srv.service @@ -0,0 +1 @@ +oui diff --git a/tests/dictionaries/80wrong_service_name/errno_76 b/tests/dictionaries/70service_engine_dash/result/tmpfiles.d/rougail.conf similarity index 100% rename from tests/dictionaries/80wrong_service_name/errno_76 rename to tests/dictionaries/70service_engine_dash/result/tmpfiles.d/rougail.conf diff --git a/tests/dictionaries/70service_engine_dash/tiramisu/base.py b/tests/dictionaries/70service_engine_dash/tiramisu/base.py new file mode 100644 index 00000000..2280252c --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/tiramisu/base.py @@ -0,0 +1,22 @@ +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 * +option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="oui", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) +option_2 = OptionDescription(name="general", doc="général", children=[option_3], properties=frozenset({"normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_6 = BoolOption(name="activate", doc="activate", default=True) +option_7 = BoolOption(name="manage", doc="manage", default=True) +option_5 = OptionDescription(name="test_srv", doc="test-srv", children=[option_6, option_7]) +option_5.impl_set_information('engine', "creole") +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/70service_engine_dash/tmpl/test-srv.service b/tests/dictionaries/70service_engine_dash/tmpl/test-srv.service new file mode 100644 index 00000000..a29cfeaf --- /dev/null +++ b/tests/dictionaries/70service_engine_dash/tmpl/test-srv.service @@ -0,0 +1 @@ +%%mode_conteneur_actif diff --git a/tests/dictionaries/80wrong_service_name/00-base.xml b/tests/dictionaries/80wrong_service_name/00-base.xml deleted file mode 100644 index a7f31c93..00000000 --- a/tests/dictionaries/80wrong_service_name/00-base.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - -