now we can personalise default setting for file et override

This commit is contained in:
2021-04-04 11:03:49 +02:00
parent 5add91082f
commit 1249276b9d
176 changed files with 553 additions and 3869 deletions

View File

@ -30,7 +30,6 @@ from typing import Tuple
from ..i18n import _
from ..utils import normalize_family
from ..error import DictConsistencyError
from ..config import RougailConfig
# a object's attribute has some annotations
# that shall not be present in the exported (flatened) XML
ERASED_ATTRIBUTES = ('redefine', 'exists', 'optional', 'remove_check', 'namespace',
@ -97,6 +96,7 @@ class ServiceAnnotator:
family = self._gen_family(eltname,
path,
service.xmlfiles,
with_informations=False,
)
if isinstance(values, dict):
values = list(values.values())
@ -165,17 +165,21 @@ class ServiceAnnotator:
dtd_key_type = elttype + '_type'
else:
dtd_key_type = key + '_type'
elt_type = getattr(elt, dtd_key_type, 'string')
if elt_type == 'variable':
elt_type = 'symlink'
family.variable.append(self._generate_element(elt_type,
dtd_key_type,
elttype,
key,
value,
elt,
f'{subpath}.{key}'
))
elt_type = getattr(elt, dtd_key_type, None)
if elt_type:
if elt_type == 'variable':
elt_type = 'symlink'
family.variable.append(self._generate_element(elt_type,
dtd_key_type,
elttype,
key,
value,
elt,
f'{subpath}.{key}'
))
else:
setattr(family.information, key, value)
family.variable.append(activate_obj)
families.append(family)
return families
@ -205,7 +209,8 @@ class ServiceAnnotator:
def _gen_family(self,
name,
path,
xmlfiles
xmlfiles,
with_informations=True,
):
family = self.objectspace.family(xmlfiles)
family.name = normalize_family(name)
@ -216,6 +221,8 @@ class ServiceAnnotator:
family,
None,
)
if with_informations:
family.information = self.objectspace.information(xmlfiles)
return family
def _generate_element(self,
@ -263,8 +270,6 @@ class ServiceAnnotator:
raise DictConsistencyError(msg, 69, override.xmlfiles)
self.uniq_overrides.append(service_name)
override.name = service_name
if not hasattr(override, 'engine'):
override.engine = RougailConfig['default_engine']
if not hasattr(override, 'source'):
override.source = f'{service_name}.service'
@ -279,8 +284,6 @@ class ServiceAnnotator:
msg = _(f'attribute "source" is mandatory for the file "{file_.name}" '
f'"({service_name})"')
raise DictConsistencyError(msg, 34, file_.xmlfiles)
if not hasattr(file_, 'engine'):
file_.engine = RougailConfig['default_engine']
def _update_ip(self,
ip,

View File

@ -229,12 +229,9 @@ class VariableAnnotator(Walk): # pylint: disable=R0903
"""Convert variable help
"""
for variable in self.get_variables():
if not hasattr(variable, 'help'):
continue
if not hasattr(variable, 'information'):
variable.information = self.objectspace.information(variable.xmlfiles)
self._convert_help(variable)
@staticmethod
def _convert_help(variable) -> None:
if hasattr(variable, 'help'):
variable.information.help = variable.help
del variable.help

View File

@ -42,9 +42,14 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
'functions_file': join(ROUGAILROOT, 'functions.py'),
'variable_namespace': 'rougail',
'auto_freeze_variable': 'server_deployed',
'default_engine': 'creole',
'internal_functions': [],
'modes_level': ['basic', 'normal', 'expert'],
'default_family_mode': 'basic',
'default_variable_mode': 'normal',
'default_files_engine': 'creole',
'default_files_mode': '0644',
'default_files_owner': 'root',
'default_files_group': 'root',
'default_files_included': 'no',
'default_overrides_engine': 'creole',
}

View File

@ -62,13 +62,13 @@
<!ATTLIST file variable CDATA #IMPLIED>
<!ATTLIST file variable_type (variable) "variable">
<!ATTLIST file source CDATA #IMPLIED>
<!ATTLIST file mode CDATA "0644">
<!ATTLIST file owner CDATA "root">
<!ATTLIST file group CDATA "root">
<!ATTLIST file mode CDATA #IMPLIED>
<!ATTLIST file owner CDATA #IMPLIED>
<!ATTLIST file group CDATA #IMPLIED>
<!ATTLIST file filelist CDATA #IMPLIED>
<!ATTLIST file redefine (True|False) "False">
<!ATTLIST file engine (none|creole|jinja2|creole_legacy) #IMPLIED>
<!ATTLIST file included (no|name|content) "no">
<!ATTLIST file included (no|name|content) #IMPLIED>
<!ELEMENT override EMPTY>
<!ATTLIST override source CDATA #IMPLIED>
@ -83,6 +83,7 @@
<!ATTLIST family mode CDATA #IMPLIED>
<!ATTLIST family hidden (True|False) "False">
<!ATTLIST family dynamic CDATA #IMPLIED>
<!ATTLIST family public CDATA #IMPLIED>
<!ELEMENT variable (value*)>
<!ATTLIST variable name CDATA #REQUIRED>
@ -101,6 +102,7 @@
<!ATTLIST variable remove_check (True|False) "False">
<!ATTLIST variable remove_condition (True|False) "False">
<!ATTLIST variable remove_fill (True|False) "False">
<!ATTLIST variable public CDATA #IMPLIED>
<!ATTLIST variable test CDATA #IMPLIED>
<!ELEMENT value (#PCDATA)>

View File

@ -34,10 +34,10 @@ from os.path import dirname, join, isfile, isdir, abspath
try:
from tiramisu3 import Config
from tiramisu3 import Config, undefined
from tiramisu3.error import PropertiesOptionError # pragma: no cover
except ModuleNotFoundError: # pragma: no cover
from tiramisu import Config
from tiramisu import Config, undefined
from tiramisu.error import PropertiesOptionError
from ..config import RougailConfig
@ -55,6 +55,11 @@ log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())
INFORMATIONS = {'files': ['source', 'mode', 'owner', 'group', 'engine', 'included'],
'overrides': ['name', 'source', 'engine'],
}
class RougailLeaderIndex:
"""This object is create when access to a specified Index of the variable
"""
@ -157,22 +162,26 @@ class RougailExtra:
For example %%extra1.family.variable
"""
def __init__(self,
suboption: Dict) -> None:
self.suboption = suboption
suboption: Dict,
) -> None:
self._suboption = suboption
def __getattr__(self,
key: str,
) -> Any:
try:
return self.suboption[key]
return self._suboption[key]
except KeyError:
raise AttributeError(f'unable to find extra "{key}"')
def __iter__(self):
return iter(self.suboption.values())
return iter(self._suboption.values())
def items(self):
return self.suboption.items()
return self._suboption.items()
def __str__(self):
return f'<extra object with: {self._suboption}>'
class RougailBaseTemplate:
@ -286,9 +295,14 @@ class RougailBaseTemplate:
chdir(self.templates_dir)
for option in await self.config.option.list(type='all'):
namespace = await option.option.name()
is_var_namespace = namespace == self.rougailconfig['variable_namespace']
is_variable_namespace = namespace == self.rougailconfig['variable_namespace']
if namespace == 'services':
is_service_namespace = 'root'
else:
is_service_namespace = False
self.rougail_variables_dict[namespace] = await self.load_variables(option,
is_var_namespace,
is_variable_namespace,
is_service_namespace,
)
for template in listdir('.'):
self.prepare_template(template)
@ -303,6 +317,7 @@ class RougailBaseTemplate:
type_ = await fills.option.name()
for fill_obj in await fills.list('all'):
fill = await fill_obj.value.dict()
await self.get_informations(type_, fill, fill_obj)
if 'included' in fill:
if (fill['included'] == 'no' and included is True) or \
(fill['included'] != 'no' and included is False):
@ -317,6 +332,19 @@ class RougailBaseTemplate:
self.post_instance()
chdir(ori_dir)
async def get_informations(self,
type_: str,
dico: dict,
obj: 'Option',
) -> None:
for key in INFORMATIONS.get(type_, []):
default_key = f'default_{type_}_{key}'
if default_key in RougailConfig:
default_value = RougailConfig[default_key]
else:
default_value = undefined
dico[key] = await obj.information.get(key, default_value)
def desactive_service(self,
service_name: str,
):
@ -345,7 +373,8 @@ class RougailBaseTemplate:
async def load_variables(self,
optiondescription,
is_variable_namespace,
is_variable_namespace: str,
is_service_namespace: str,
) -> RougailExtra:
"""Load all variables and set it in RougailExtra objects
"""
@ -366,8 +395,18 @@ class RougailBaseTemplate:
)
variables[leader_name] = leader
else:
if is_service_namespace == 'root':
new_is_service_namespace = 'service_name'
elif is_service_namespace == 'service_name':
new_is_service_namespace = await option.option.name()
elif is_service_namespace in INFORMATIONS:
# remove 's'
new_is_service_namespace = is_service_namespace[:-1]
else:
new_is_service_namespace = is_service_namespace
subfamilies = await self.load_variables(option,
is_variable_namespace,
new_is_service_namespace,
)
variables[await option.option.name()] = subfamilies
else:
@ -382,4 +421,9 @@ class RougailBaseTemplate:
else:
value = await option.value.get()
variables[await option.option.name()] = value
if isinstance(is_service_namespace, str) and is_service_namespace + 's' in INFORMATIONS:
await self.get_informations(is_service_namespace + 's',
variables,
optiondescription,
)
return RougailExtra(variables)