This commit is contained in:
egarette@silique.fr 2023-10-12 08:17:30 +02:00
parent 940b20f5d9
commit 4fc32c7624
2926 changed files with 49970 additions and 14561 deletions

View file

@ -58,7 +58,7 @@ def get_annotators(annotators, module_name):
annotators[module_name] = [] annotators[module_name] = []
for pathobj in importlib.resources.files(module_name).iterdir(): for pathobj in importlib.resources.files(module_name).iterdir():
path = str(pathobj) path = str(pathobj)
if path.endswith('__') or path.endswith('__.py'): if not path.endswith('.py') or path.endswith('__.py'):
continue continue
module = load_modules(path) module = load_modules(path)
if 'Annotator' not in dir(module): if 'Annotator' not in dir(module):
@ -84,13 +84,17 @@ class SpaceAnnotator: # pylint: disable=R0903
for extra_annotator in objectspace.rougailconfig['extra_annotators']: for extra_annotator in objectspace.rougailconfig['extra_annotators']:
annotators.extend(ANNOTATORS[extra_annotator]) annotators.extend(ANNOTATORS[extra_annotator])
annotators = sorted(annotators, key=get_level) annotators = sorted(annotators, key=get_level)
functions = [] functions = {}
functions_files = objectspace.rougailconfig['functions_file'] functions_files = objectspace.rougailconfig['functions_file']
if not isinstance(functions_files, list): if not isinstance(functions_files, list):
functions_files = [functions_files] functions_files = [functions_files]
for functions_file in functions_files: for functions_file in functions_files:
if isfile(functions_file): if isfile(functions_file):
functions.extend(dir(load_modules(functions_file))) loaded_modules = load_modules(functions_file)
for function in dir(loaded_modules):
if function.startswith('_'):
continue
functions[function] = getattr(loaded_modules, function)
for annotator in annotators: for annotator in annotators:
annotator(objectspace, annotator(objectspace,
functions, functions,

View file

@ -48,6 +48,7 @@ class Annotator(TargetAnnotator, ParamAnnotator):
functions, functions,
*args, *args,
): ):
return
self.objectspace = objectspace self.objectspace = objectspace
self.only_variable = True self.only_variable = True
self.target_is_uniq = False self.target_is_uniq = False

View file

@ -52,24 +52,22 @@ class Annotator(TargetAnnotator, ParamAnnotator, Walk):
*args, *args,
): ):
self.objectspace = objectspace self.objectspace = objectspace
self.target_is_uniq = False # self.target_is_uniq = False
self.only_variable = False # self.only_variable = False
self.allow_function = False # self.allow_function = False
self.force_service_value = {} # self.force_service_value = {}
if hasattr(objectspace.space, 'variables'): #for path_prefix, constraints in self.get_constraints():
self.convert_auto_freeze() # if not hasattr(constraints, 'condition'):
for path_prefix, constraints in self.get_constraints(): # continue
if not hasattr(constraints, 'condition'): # self.convert_target(constraints.condition, path_prefix)
continue # self.check_condition_optional(constraints, path_prefix)
self.convert_target(constraints.condition, path_prefix) # self.convert_condition_source(constraints, path_prefix)
self.check_condition_optional(constraints, path_prefix) # self.convert_param(constraints.condition, path_prefix)
self.convert_condition_source(constraints, path_prefix) # self.check_source_target(constraints)
self.convert_param(constraints.condition, path_prefix) # self.convert_xxxlist(constraints, path_prefix)
self.check_source_target(constraints) # self.check_choice_option_condition(constraints, path_prefix)
self.convert_xxxlist(constraints, path_prefix) # self.remove_condition_with_empty_target(constraints)
self.check_choice_option_condition(constraints, path_prefix) # self.convert_condition(constraints, path_prefix)
self.remove_condition_with_empty_target(constraints)
self.convert_condition(constraints, path_prefix)
def valid_type_validation(self, def valid_type_validation(self,
obj, obj,
@ -78,47 +76,6 @@ class Annotator(TargetAnnotator, ParamAnnotator, Walk):
return None return None
return obj.source.type return obj.source.type
def convert_auto_freeze(self):
"""convert auto_freeze
only if auto_freeze_variable is True this variable is frozen
"""
for variable in self.get_variables():
if not variable.auto_freeze and not variable.auto_save:
continue
#if variable.namespace != self.objectspace.rougailconfig['variable_namespace']:
# msg = _(f'auto_freeze is not allowed in extra "{variable.namespace}"')
# raise DictConsistencyError(msg, 49, variable.xmlfiles)
variable.force_store_value = True
if variable.auto_save:
continue
auto_freeze_variable = self.objectspace.rougailconfig['auto_freeze_variable']
if not self.objectspace.paths.path_is_defined(auto_freeze_variable,
self.objectspace.rougailconfig['variable_namespace'],
variable.path_prefix,
):
msg = _(f'the variable "{variable.name}" is auto_freeze but there is no variable "{auto_freeze_variable}"')
raise DictConsistencyError(msg, 81, variable.xmlfiles)
new_condition = self.objectspace.condition(variable.xmlfiles)
new_condition.name = 'auto_frozen_if_in'
new_condition.namespace = variable.namespace
new_condition.source = auto_freeze_variable
new_param = self.objectspace.param(variable.xmlfiles)
new_param.text = True
new_condition.param = [new_param]
new_target = self.objectspace.target(variable.xmlfiles)
new_target.type = 'variable'
path = variable.path
if variable.path_prefix:
path = path.split('.', 1)[-1]
new_target.name = path
new_condition.target = [new_target]
path_prefix, constraints = next(self.get_constraints(create=True,
path_prefix=variable.path_prefix,
))
if not hasattr(constraints, 'condition'):
constraints.condition = []
constraints.condition.append(new_condition)
def check_source_target(self, constraints): def check_source_target(self, constraints):
"""verify that source != target in condition """verify that source != target in condition
""" """
@ -404,7 +361,7 @@ class Annotator(TargetAnnotator, ParamAnnotator, Walk):
main_action, main_action,
) )
if isinstance(leader_or_variable, self.objectspace.variable) and \ if isinstance(leader_or_variable, self.objectspace.variable) and \
(leader_or_variable.auto_save or leader_or_variable.auto_freeze) and \ leader_or_variable.auto_save and \
'force_default_on_freeze' in actions: 'force_default_on_freeze' in actions:
continue continue
for action in actions[1:]: for action in actions[1:]:

View file

@ -54,8 +54,9 @@ class Annotator(Walk):
objectspace, objectspace,
*args, *args,
): ):
self.mode_auto = []
self.objectspace = objectspace self.objectspace = objectspace
if not hasattr(self.objectspace.space, 'variables'): if not self.objectspace.paths:
return return
self.modes = {name: Mode(idx) for idx, name in enumerate(self.objectspace.rougailconfig['modes_level'])} self.modes = {name: Mode(idx) for idx, name in enumerate(self.objectspace.rougailconfig['modes_level'])}
self.remove_empty_families() self.remove_empty_families()
@ -67,34 +68,34 @@ class Annotator(Walk):
def remove_empty_families(self) -> None: def remove_empty_families(self) -> None:
"""Remove all families without any variable """Remove all families without any variable
""" """
removed_families = {} removed_families = []
for family, parent in self.get_families(with_parent=True): for family in self.get_families():
if isinstance(family, self.objectspace.family) and not self._has_variable(family): if isinstance(family, self.objectspace.family) and not self._has_variable(family.path):
removed_families.setdefault(parent, []).append(family) if '.' in family.path:
for parent, families in removed_families.items(): removed_families.append(family.path)
for family in families: removed_families.reverse()
del parent.variable[family.name] for family in removed_families:
self.objectspace.del_family(family)
def _has_variable(self, def _has_variable(self,
family: 'self.objectspace.family', family: str,
) -> bool: ) -> bool:
if hasattr(family, 'variable'): for variable in self.objectspace.parents[family]:
for variable in family.variable.values(): if variable in self.objectspace.families:
if isinstance(variable, self.objectspace.family): if self._has_variable(variable):
if self._has_variable(variable):
return True
else:
return True return True
else:
return True
return False return False
def family_names(self) -> None: def family_names(self) -> None:
"""Set doc, path, ... to family """Set doc, path, ... to family
""" """
for family in self.get_families(): for family in self.get_families():
if not hasattr(family, 'description'): if not family.description:
family.description = family.name family.description = family.name
family.doc = family.description # family.doc = family.description
del family.description # del family.description
def change_modes(self): def change_modes(self):
"""change the mode of variables """change the mode of variables
@ -130,17 +131,21 @@ class Annotator(Walk):
def _set_default_mode(self, def _set_default_mode(self,
family: 'self.objectspace.family', family: 'self.objectspace.family',
) -> None: ) -> None:
if not hasattr(family, 'variable'): children = self.objectspace.parents[family.path]
if not children:
return return
if self._has_mode(family): if self._has_mode(family):
family_mode = family.mode family_mode = family.mode
else: else:
family_mode = None family_mode = None
leader = None leader = None
for variable in family.variable.values(): for variable_path in children:
if leader is None and hasattr(family, 'leadership') and family.leadership: variable = self.objectspace.paths[variable_path]
if variable.type == 'symlink':
continue
if leader is None and family.type == 'leadership':
leader = variable leader = variable
if isinstance(variable, self.objectspace.family): if variable_path in self.objectspace.families:
# set default mode a subfamily # set default mode a subfamily
if family_mode and not self._has_mode(variable): if family_mode and not self._has_mode(variable):
self._set_auto_mode(variable, family_mode) self._set_auto_mode(variable, family_mode)
@ -154,32 +159,33 @@ class Annotator(Walk):
# here because follower can change leader mode # here because follower can change leader mode
self._set_auto_mode(family, leader.mode) self._set_auto_mode(family, leader.mode)
@staticmethod def _has_mode(self, obj) -> bool:
def _has_mode(obj) -> bool: return obj.mode and not obj.path in self.mode_auto
return 'mode' in vars(obj) and not hasattr(obj, 'mode_auto')
def _set_default_mode_variable(self, def _set_default_mode_variable(self,
variable: 'self.objectspace.variable', variable: 'self.objectspace.variable',
family_mode: str, family_mode: str,
) -> None: ) -> None:
# auto_save or auto_freeze variable is set to 'basic' mode # auto_save variable is set to 'basic' mode
# if its mode is not defined by the user # if its mode is not defined by the user
if not self._has_mode(variable) and \ if not self._has_mode(variable) and \
(variable.auto_save is True or variable.auto_freeze is True): variable.auto_save is True:
variable.mode = self.objectspace.rougailconfig['modes_level'][0] variable.mode = self.objectspace.rougailconfig['modes_level'][0]
# mandatory variable without value is a basic variable # mandatory variable without value is a basic variable
elif not self._has_mode(variable) and \ elif not self._has_mode(variable) and \
variable.mandatory is True and \ variable.mandatory is True and \
not hasattr(variable, 'default') and \ variable.default is None and \
not hasattr(variable, 'default_multi'): variable.path not in self.objectspace.default_multi:
variable.mode = self.objectspace.rougailconfig['modes_level'][0] variable.mode = self.objectspace.rougailconfig['modes_level'][0]
elif family_mode and not self._has_mode(variable): elif family_mode and not self._has_mode(variable):
self._set_auto_mode(variable, family_mode) self._set_auto_mode(variable, family_mode)
@staticmethod def _set_auto_mode(self,
def _set_auto_mode(obj, mode: str) -> None: obj,
mode: str,
) -> None:
obj.mode = mode obj.mode = mode
obj.mode_auto = True self.mode_auto.append(obj.path)
def _set_default_mode_leader(self, def _set_default_mode_leader(self,
leader: 'self.objectspace.variable', leader: 'self.objectspace.variable',
@ -188,12 +194,9 @@ class Annotator(Walk):
if follower.auto_save is True: if follower.auto_save is True:
msg = _(f'leader/followers "{follower.name}" could not be auto_save') msg = _(f'leader/followers "{follower.name}" could not be auto_save')
raise DictConsistencyError(msg, 29, follower.xmlfiles) raise DictConsistencyError(msg, 29, follower.xmlfiles)
if follower.auto_freeze is True:
msg = f'leader/followers "{follower.name}" could not be auto_freeze'
raise DictConsistencyError(_(msg), 30, follower.xmlfiles)
if leader == follower: if leader == follower:
# it's a leader # it's a leader
if not hasattr(leader, 'mode'): if not leader.mode:
self._set_auto_mode(leader, self.objectspace.rougailconfig['default_variable_mode']) self._set_auto_mode(leader, self.objectspace.rougailconfig['default_variable_mode'])
return return
if self._has_mode(follower): if self._has_mode(follower):
@ -215,44 +218,42 @@ class Annotator(Walk):
def _change_family_mode(self, def _change_family_mode(self,
family: 'self.objectspace.family', family: 'self.objectspace.family',
) -> None: ) -> None:
if hasattr(family, 'mode'): if family.mode:
family_mode = family.mode family_mode = family.mode
else: else:
family_mode = self.objectspace.rougailconfig['default_family_mode'] family_mode = self.objectspace.rougailconfig['default_family_mode']
min_variable_mode = self.objectspace.rougailconfig['modes_level'][-1] min_variable_mode = self.objectspace.rougailconfig['modes_level'][-1]
# change variable mode, but not if variables are not in a family # change variable mode, but not if variables are not in a family
is_leadership = hasattr(family, 'leadership') and family.leadership is_leadership = family.type == 'leadership'
if hasattr(family, 'variable'): if family.path in self.objectspace.parents:
for idx, variable in enumerate(family.variable.values()): for idx, variable_path in enumerate(self.objectspace.parents[family.path]):
if isinstance(variable, self.objectspace.family): variable = self.objectspace.paths[variable_path]
if not hasattr(variable, 'mode'): if variable.type == 'symlink':
continue
if variable_path in self.objectspace.families:
if not variable.mode:
variable.mode = self.objectspace.rougailconfig['default_family_mode'] variable.mode = self.objectspace.rougailconfig['default_family_mode']
#elif idx == 0 and is_leadership:
# variable.mode = None
# if variable.path == 'general.piwigo.users.piwigo_users':
# print(variable.path)
# continue
else: else:
self._change_variable_mode(variable, family_mode, is_leadership) self._change_variable_mode(variable, family_mode, is_leadership)
if self.modes[min_variable_mode] > self.modes[variable.mode]: if self.modes[min_variable_mode] > self.modes[variable.mode]:
min_variable_mode = variable.mode min_variable_mode = variable.mode
if not isinstance(family, (self.objectspace.family, self.objectspace.variables)): #FIXME if not isinstance(family, (self.objectspace.family, self.objectspace.variables)):
# it's Variable, Service, ... # # it's Variable, Service, ...
return # return
if not hasattr(family, 'mode'): if not family.mode:
# set the lower variable mode to family # set the lower variable mode to family
self._set_auto_mode(family, min_variable_mode) self._set_auto_mode(family, min_variable_mode)
if not is_leadership and family.mode != min_variable_mode: #FIXME if not is_leadership and family.mode != min_variable_mode:
msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and ' #FIXME msg = _(f'the family "{family.name}" is in "{family.mode}" mode but variables and '
f'families inside have the higher modes "{min_variable_mode}"') #FIXME f'families inside have the higher modes "{min_variable_mode}"')
raise DictConsistencyError(msg, 62, family.xmlfiles) #FIXME raise DictConsistencyError(msg, 62, family.xmlfiles)
def _change_variable_mode(self, def _change_variable_mode(self,
variable, variable,
family_mode: str, family_mode: str,
is_follower: bool, is_follower: bool,
) -> None: ) -> None:
if hasattr(variable, 'mode'): if variable.mode:
variable_mode = variable.mode variable_mode = variable.mode
else: else:
variable_mode = self.objectspace.rougailconfig['default_variable_mode'] variable_mode = self.objectspace.rougailconfig['default_variable_mode']
@ -263,28 +264,21 @@ class Annotator(Walk):
f'but family has the higher family mode "{family_mode}"') f'but family has the higher family mode "{family_mode}"')
raise DictConsistencyError(msg, 61, variable.xmlfiles) raise DictConsistencyError(msg, 61, variable.xmlfiles)
self._set_auto_mode(variable, family_mode) self._set_auto_mode(variable, family_mode)
if not hasattr(variable, 'mode'): if not variable.mode:
variable.mode = variable_mode variable.mode = variable_mode
def dynamic_families(self): def dynamic_families(self):
"""link dynamic families to object """link dynamic families to object
""" """
for family in self.get_families(): for family in self.get_families():
if 'dynamic' not in vars(family): if family.type != 'dynamic':
continue continue
family.suffixes = self.objectspace.paths.get_variable(family.dynamic, family.variable = self.objectspace.paths[family.variable]
family.namespace, if not family.variable.multi:
xmlfiles=family.xmlfiles,
allow_variable_namespace=True,
force_path_prefix=family.path_prefix,
add_path_prefix=True,
)
del family.dynamic
if not family.suffixes.multi:
msg = _(f'dynamic family "{family.name}" must be linked ' msg = _(f'dynamic family "{family.name}" must be linked '
f'to multi variable') f'to multi variable')
raise DictConsistencyError(msg, 16, family.xmlfiles) raise DictConsistencyError(msg, 16, family.xmlfiles)
for variable in family.variable.values(): for variable in self.objectspace.parents[family.path]:
if isinstance(variable, self.objectspace.family) and not variable.leadership: if isinstance(variable, self.objectspace.family) and not variable.leadership:
msg = _(f'dynamic family "{family.name}" cannot contains another family') msg = _(f'dynamic family "{family.name}" cannot contains another family')
raise DictConsistencyError(msg, 22, family.xmlfiles) raise DictConsistencyError(msg, 22, family.xmlfiles)
@ -293,9 +287,7 @@ class Annotator(Walk):
"""Convert variable help """Convert variable help
""" """
for family in self.get_families(): for family in self.get_families():
if not hasattr(family, 'help'): if not family.help:
continue continue
if not hasattr(family, 'information'): self.objectspace.informations.add(family.path, 'help', family.help)
family.information = self.objectspace.information(family.xmlfiles)
family.information.help = family.help
del family.help del family.help

View file

@ -41,14 +41,13 @@ from jinja2.utils import missing
class CollectUndefined(Undefined): class CollectUndefined(Undefined):
def __init__( def __init__(self,
self, hint=None,
hint=None, obj=missing,
obj=missing, name=None,
name=None, exc=UndefinedError,
exc=UndefinedError, subname=None,
subname=None, ) -> None:
) -> None:
self._undefined_hint = hint self._undefined_hint = hint
self._undefined_obj = obj self._undefined_obj = obj
self._undefined_name = name self._undefined_name = name
@ -67,42 +66,51 @@ class CollectUndefined(Undefined):
def get_jinja_variable_to_param(jinja_text, def get_jinja_variable_to_param(jinja_text,
objectspace, objectspace,
obj, xmlfiles,
path_prefix, path_prefix,
functions,
variable_name, variable_name,
variable_path, variable_path,
): ):
CollectUndefined.variables = set() CollectUndefined.variables = set()
try: try:
SandboxedEnvironment(loader=DictLoader({'tmpl': jinja_text}), undefined=CollectUndefined).get_template('tmpl').render() env = SandboxedEnvironment(loader=DictLoader({'tmpl': jinja_text}), undefined=CollectUndefined)
#add functions as filters
env.filters = functions
# and functions
env.get_template('tmpl').render(**functions)
except UndefinedError as err: except UndefinedError as err:
msg = _(f'error in jinja "{jinja_text}": {err}') msg = _(f'error in jinja "{jinja_text}": {err}')
raise DictConsistencyError(msg, 91, obj.xmlfiles) from err raise DictConsistencyError(msg, 91, xmlfiles) from err
variables = list(CollectUndefined.variables) variables = list(CollectUndefined.variables)
variables.sort() variables.sort()
for variable in variables: for variable in variables:
new_param = objectspace.param(obj.xmlfiles) #new_param = objectspace.param(obj.xmlfiles)
if variable in [variable_name, variable_path]: #if variable in [variable_name, variable_path]:
new_param.name = '__internal_key' # new_param.name = '__internal_key'
new_param.type = 'string' # new_param.type = 'string'
new_param.text = variable # new_param.text = variable
else: #else:
new_param.name = variable if variable in ['__suffix', '__index']:
new_param.text = variable yield variable
try: if variable in objectspace.variables:
set_variable_to_param(new_param, yield objectspace.paths[variable]
objectspace, #new_param.name = variable
None, #new_param.text = variable
obj.namespace, #try:
path_prefix, # set_variable_to_param(new_param,
None, # objectspace,
) # None,
except DictConsistencyError as err: # obj.namespace,
if err.errno != 42: # path_prefix,
raise err from err # None,
continue # )
new_param.type = 'variable' #except DictConsistencyError as err:
obj.param.append(new_param) # if err.errno != 42:
# raise err from err
# continue
#new_param.type = 'variable'
#obj.param.append(new_param)
CALC_MULTI = ('calc_value', CALC_MULTI = ('calc_value',
@ -130,6 +138,7 @@ class Annotator(TargetAnnotator, ParamAnnotator):
functions, functions,
*args, *args,
): ):
return
self.objectspace = objectspace self.objectspace = objectspace
self.functions = copy(functions) self.functions = copy(functions)
self.functions.extend(self.objectspace.rougailconfig['internal_functions']) self.functions.extend(self.objectspace.rougailconfig['internal_functions'])

View file

@ -1,85 +0,0 @@
"""Annotate group
Created by:
EOLE (http://eole.orion.education.fr)
Copyright (C) 2005-2018
Forked by:
Cadoles (http://www.cadoles.com)
Copyright (C) 2019-2021
Silique (https://www.silique.fr)
Copyright (C) 2022-2023
distribued with GPL-2 or later license
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
from rougail.i18n import _
from rougail.error import DictConsistencyError
from rougail.utils import normalize_family
from rougail.annotator.variable import Walk
class Annotator(Walk):
"""Annotate group
"""
level = 10
def __init__(self,
objectspace,
*args,
):
if not hasattr(objectspace.space, 'variables'):
return
self.objectspace = objectspace
self.convert_groups()
def convert_groups(self): # pylint: disable=C0111
"""convert groups
"""
# store old leaders family name
for family in self.get_families():
if not isinstance(family, self.objectspace.family):
continue
if not family.leadership:
continue
if hasattr(family, 'dynamic'):
msg = _(f'the family "{family.name}" cannot be leadership and dynamic together')
raise DictConsistencyError(msg, 31, family.xmlfiles)
if not hasattr(family, 'variable'):
continue
for idx, variable in enumerate(family.variable.values()):
if idx == 0:
# it's a leader
if variable.multi is not True:
msg = _(f'the variable "{variable.name}" in a leadership must be multi')
raise DictConsistencyError(msg, 32, variable.xmlfiles)
if variable.hidden:
family.hidden = variable.hidden
elif family.hidden:
variable.hidden = family.hidden
if variable.hidden:
variable.frozen = True
variable.force_default_on_freeze = True
variable.hidden = None
else:
# it's a follower
if family.hidden:
variable.frozen = True
variable.force_default_on_freeze = True
if variable.multi is True:
variable.multi = 'submulti'
else:
variable.multi = True

View file

@ -45,88 +45,87 @@ class Annotator(Walk):
*args *args
) -> None: ) -> None:
self.objectspace = objectspace self.objectspace = objectspace
services = [] # services = []
if not self.objectspace.paths.has_path_prefix() and hasattr(self.objectspace.space, 'services'): # if not self.objectspace.paths.has_path_prefix() and hasattr(self.objectspace.space, 'services'):
services.append(self.objectspace.space.services) # services.append(self.objectspace.space.services)
elif hasattr(self.objectspace.space, 'variables'): # elif hasattr(self.objectspace.space, 'variables'):
for path_prefix in self.objectspace.paths.get_path_prefixes(): # for path_prefix in self.objectspace.paths.get_path_prefixes():
if path_prefix in self.objectspace.space.variables and \ # if path_prefix in self.objectspace.space.variables and \
hasattr(self.objectspace.space.variables[path_prefix], 'services'): # hasattr(self.objectspace.space.variables[path_prefix], 'services'):
services.append(self.objectspace.space.variables[path_prefix].services) # services.append(self.objectspace.space.variables[path_prefix].services)
for service in services: if self.objectspace.paths:
self.convert_services(service) for family in self.get_families():
if hasattr(self.objectspace.space, 'variables'): #if family.path != 'services' and not family.path.startswith('services.'):
if family.path != 'services':
continue
self.convert_services(family)
self.convert_family() self.convert_family()
self.convert_variable() self.convert_variable()
def convert_property(self,
variable,
) -> None:
"""convert properties
"""
# hidden variable is also frozen
if isinstance(variable, self.objectspace.variable) and variable.hidden is True and \
variable.name != self.objectspace.rougailconfig['auto_freeze_variable']:
if not variable.auto_freeze and \
not hasattr(variable, 'provider') and not hasattr(variable, 'supplier'):
variable.frozen = True
if not variable.auto_save and \
not variable.auto_freeze and \
'force_default_on_freeze' not in vars(variable) and \
not hasattr(variable, 'provider') and not hasattr(variable, 'supplier'):
variable.force_default_on_freeze = True
if not hasattr(variable, 'properties'):
variable.properties = []
if 'mandatory' in vars(variable) and not variable.mandatory and variable.multi:
# a multi could not have "None" has value
# to permit it, just add mandatory="False"
variable.properties.append('notempty')
for prop in PROPERTIES:
if hasattr(variable, prop):
if getattr(variable, prop) is True:
# for subprop in CONVERT_PROPERTIES.get(prop, [prop]):
variable.properties.append(prop)
setattr(variable, prop, None)
if hasattr(variable, 'unique') and variable.unique != 'nil':
if variable.unique == 'False' or variable.unique is False:
variable.properties.append('notunique')
else:
variable.properties.append('unique')
if hasattr(variable, 'mode') and variable.mode:
variable.properties.append(variable.mode)
variable.mode = None
if 'force_store_value' in variable.properties and \
'force_default_on_freeze' in variable.properties: # pragma: no cover
# should not appened
msg = _('cannot have auto_freeze or auto_save with the hidden '
f'variable "{variable.name}"')
raise DictConsistencyError(msg, 50, variable.xmlfiles)
if not variable.properties:
del variable.properties
def convert_services(self, services) -> None: def convert_services(self, services) -> None:
"""convert services """convert services
""" """
self.convert_property(services) self._convert_property(services)
for services_ in services.service.values():
self.convert_property(services_)
for service in vars(services_).values():
if not isinstance(service, self.objectspace.family):
continue
self.convert_property(service)
for family in service.family:
self.convert_property(family)
for variable in family.variable:
self.convert_property(variable)
def convert_family(self) -> None: def convert_family(self) -> None:
"""convert families """convert families
""" """
for family in self.get_families(): for family in self.get_families():
self.convert_property(family) if family.path == 'services' or family.path.startswith('services.'):
continue
self._convert_property(family)
def convert_variable(self) -> None: def convert_variable(self) -> None:
"""convert variables """convert variables
""" """
for variable in self.get_variables(): for variable in self.get_variables():
self.convert_property(variable) if variable.path.startswith('services.'):
continue
if variable.type == 'symlink':
continue
self._convert_variable_property(variable)
def _convert_variable_property(self,
variable: dict,
) -> None:
"""convert properties
"""
path = variable.path
# hidden variable is also frozen
if variable.hidden is True:
if variable.provider is None and \
variable.supplier is None:
self.objectspace.properties.append(variable.path, 'frozen')
if not variable.auto_save and \
'force_default_on_freeze' not in self.objectspace.properties[path] and \
variable.provider is None and variable.supplier is None:
self.objectspace.properties.append(path, 'force_default_on_freeze')
if not variable.mandatory and variable.multi:
# a multi could not have "None" has value
# to permit it, just add mandatory="False"
self.objectspace.properties.append(path, 'notempty')
if variable.unique is not None:
if variable.unique is False:
self.objectspace.properties.append(path, 'notunique')
else:
self.objectspace.properties.append(path, 'unique')
if variable.auto_save:
self.objectspace.properties.append(variable.path, 'force_store_value')
if 'force_store_value' in self.objectspace.properties[path] and \
'force_default_on_freeze' in self.objectspace.properties[path]: # pragma: no cover
# should not appened
msg = _('cannot have auto_save with the hidden '
f'variable "{variable.name}"')
raise DictConsistencyError(msg, 50, variable.xmlfiles)
self._convert_property(variable)
def _convert_property(self,
obj: dict,
) -> None:
for prop in PROPERTIES:
if hasattr(obj, prop) and getattr(obj, prop) is True:
self.objectspace.properties.append(obj.path, prop)
if obj.mode:
self.objectspace.properties.append(obj.path, obj.mode)

View file

@ -33,7 +33,8 @@ from typing import Tuple
from rougail.i18n import _ from rougail.i18n import _
from rougail.utils import normalize_family from rougail.utils import normalize_family
from rougail.error import DictConsistencyError from rougail.error import DictConsistencyError
from rougail.annotator.variable import CONVERT_OPTION #from rougail.annotator.variable import CONVERT_OPTION
from tiramisu import PermissionsOption, UsernameOption
try: try:
import tiramisu4 as tiramisu import tiramisu4 as tiramisu
except ModuleNotFoundError: except ModuleNotFoundError:
@ -48,13 +49,6 @@ FORCE_INFORMATIONS = ['mode']
class Annotator: class Annotator:
"""Manage service's object """Manage service's object
for example::
<services>
<service name="test">
<service_access service='ntp'>
</service_access>
</service>
</services>
""" """
level = 20 level = 20
def __init__(self, def __init__(self,
@ -63,238 +57,373 @@ class Annotator:
) -> None: ) -> None:
self.objectspace = objectspace self.objectspace = objectspace
self.uniq_overrides = {} self.uniq_overrides = {}
if 'network_type' not in self.objectspace.types: #if 'network_type' not in self.objectspace.types:
self.objectspace.types['network_type'] = self.objectspace.types['ip_type'] # self.objectspace.types['network_type'] = self.objectspace.types['ip_type']
services = [] services = []
if not self.objectspace.paths.has_path_prefix(): if 1:
#FIXME if not self.objectspace.paths.has_path_prefix():
self.uniq_overrides[None] = [] self.uniq_overrides[None] = []
if hasattr(self.objectspace.space, 'services'): # if hasattr(self.objectspace.space, 'services'):
if not hasattr(self.objectspace.space.services, 'service'): if self.objectspace.services:
del self.objectspace.space.services services.append((None, 'services', self.objectspace.services))
else: #elif hasattr(self.objectspace.space, 'variables'):
services.append((None, 'services', self.objectspace.space.services)) # for path_prefix in self.objectspace.paths.get_path_prefixes():
elif hasattr(self.objectspace.space, 'variables'): # self.uniq_overrides[path_prefix] = []
for path_prefix in self.objectspace.paths.get_path_prefixes(): # root_path = f'{path_prefix}.services'
self.uniq_overrides[path_prefix] = [] # if not path_prefix in self.objectspace.space.variables or \
root_path = f'{path_prefix}.services' # not hasattr(self.objectspace.space.variables[path_prefix], 'services'):
if not path_prefix in self.objectspace.space.variables or \ # continue
not hasattr(self.objectspace.space.variables[path_prefix], 'services'): # if not hasattr(self.objectspace.space.variables[path_prefix].services, 'service'):
continue # del self.objectspace.space.variables[path_prefix].services
if not hasattr(self.objectspace.space.variables[path_prefix].services, 'service'): # else:
del self.objectspace.space.variables[path_prefix].services # services.append((path_prefix, root_path, self.objectspace.space.variables[path_prefix].services))
else: if services:
services.append((path_prefix, root_path, self.objectspace.space.variables[path_prefix].services)) self.objectspace.add_family('.',
for path_prefix, root_path, service in services: 'services',
self.convert_services(path_prefix, root_path, service) 'services',
{'doc': 'services',
'hidden': True,
},
[]
)
for path_prefix, root_path, service in services:
self.convert_services(path_prefix, root_path, service)
def convert_services(self, path_prefix, root_path, services): def convert_services(self, path_prefix, root_path, services):
"""convert services to variables """convert services to variables
""" """
services.hidden = True for service_name, service in services.items():
services.name = 'services' n_service_name = normalize_family(service_name)
services.doc = 'services' path = f'{root_path}.{n_service_name}'
services.path = root_path self.objectspace.add_family(root_path,
for service_name, service in services.service.items(): path,
service.name = normalize_family(service_name) n_service_name,
activate_obj = self._generate_element('boolean', {'doc': service_name},
None, service.xmlfiles,
None, )
'activate', for typ in ['ip', 'certificates', 'files']:
not service.disabled, if typ == 'ip':
service, obj_typ = 'ips'
f'{root_path}.{service.name}',
path_prefix,
)
service.disabled = None
dico = dict(vars(service))
if 'type' not in dico:
if service.manage:
dico['type'] = service.type
else: else:
dico['type'] = 'none' obj_typ = typ
for elttype, values in dico.items(): values = getattr(self.objectspace, obj_typ)
if elttype == 'servicelist': if path in values:
self.objectspace.paths.list_conditions[path_prefix].setdefault('servicelist', obj_path = f'{path}.{typ}'
{}).setdefault( if obj_path not in self.objectspace.paths:
values, self.objectspace.add_family(path,
[]).append(activate_obj) obj_path,
continue typ,
{},
service.xmlfiles,
)
function = getattr(self, f'convert_service_{typ}')
for obj in values[path]:
function(obj,
obj_path,
n_service_name,
path_prefix,
)
self._generate_element('boolean',
None,
None,
'activate',
not service.disabled,
service,
path,
path_prefix,
)
for elttype, values in service:
if elttype in ERASED_ATTRIBUTES: if elttype in ERASED_ATTRIBUTES:
continue continue
if not service.manage and elttype not in ALLOW_ATTRIBUT_NOT_MANAGE and (elttype != 'type' or values != 'none'): if not service.manage and elttype not in ALLOW_ATTRIBUT_NOT_MANAGE and (elttype != 'type' or values is not None):
msg = _(f'unmanage service cannot have "{elttype}"') msg = _(f'unmanage service cannot have "{elttype}"')
raise DictConsistencyError(msg, 66, service.xmlfiles) raise DictConsistencyError(msg, 66, service.xmlfiles)
if isinstance(values, (dict, list)): if values:
if elttype != 'ip': self.objectspace.informations.add(path, elttype, values)
eltname = elttype + 's' self.objectspace.add_variable(path,
else: f'{path}.manage',
eltname = elttype 'manage',
if hasattr(service, 'servicelist'): {'type': 'boolean',
if isinstance(values, dict): 'default': True,
for key, value in values.items(): },
setattr(value, 'servicelist', service.servicelist) service.xmlfiles,
family = self._gen_family(eltname,
f'{root_path}.{service.name}',
service.xmlfiles,
path_prefix,
with_informations=False,
)
if isinstance(values, dict):
values = list(values.values())
family.family = self.make_group_from_elts(service_name,
elttype,
values,
f'{root_path}.{service.name}.{eltname}',
root_path,
path_prefix,
)
setattr(service, elttype, family)
else:
if not hasattr(service, 'information'):
service.information = self.objectspace.information(service.xmlfiles)
setattr(service.information, elttype, values)
service.path = f'{root_path}.{service.name}'
manage = self._generate_element('boolean',
None,
None,
'manage',
service.manage,
service,
f'{root_path}.{service.name}',
path_prefix,
)
service.variable = [activate_obj, manage]
service.doc = service_name
def make_group_from_elts(self,
service_name,
elttype,
elts,
path,
root_path,
path_prefix,
):
"""Splits each objects into a group (and `OptionDescription`, in tiramisu terms)
and build elements and its attributes (the `Options` in tiramisu terms)
"""
families = []
listname = '{}list'.format(elttype)
for elt in elts:
# try to launch _update_xxxx() function
update_elt = '_update_' + elttype
if hasattr(self, update_elt):
getattr(self, update_elt)(elt,
service_name,
path_prefix,
) )
c_name, subpath = self._get_name_path(elt,
path, def convert_service_ip(self,
root_path, ip: dict,
path_prefix, subpath: str,
) service_name: str,
family = self._gen_family(c_name, path_prefix: str,
subpath.rsplit('.', 1)[0], ) -> None:
elt.xmlfiles, variable = self.objectspace.paths[ip.name]
path_prefix, if variable.type not in ['ip', 'network', 'network_cidr']:
msg = _(f'ip cannot be linked to "{variable.type}" variable "{ip.name}"')
raise DictConsistencyError(msg, 70, ip.xmlfiles)
if variable.type in ['ip', 'network_cidr'] and ip.netmask:
msg = _(f'ip with ip_type "{variable.type}" must not have netmask')
raise DictConsistencyError(msg, 59, ip.xmlfiles)
if variable.type == 'network' and not ip.netmask:
msg = _(f'ip with ip_type "{variable.type}" must have netmask')
raise DictConsistencyError(msg, 64, ip.xmlfiles)
if ip.netmask:
netmask = self.objectspace.paths[ip.netmask]
if netmask.type != 'netmask':
msg = _(f'netmask in ip must have type "netmask", not "{netmask.type}"')
raise DictConsistencyError(msg, 65, ip.xmlfiles)
name = normalize_family(ip.name)
path = f'{subpath}.{name}'
self.objectspace.add_family(subpath,
path,
name,
{'doc': ip.name},
ip.xmlfiles,
)
self.objectspace.add_variable(path,
f'{path}.name',
'name',
{'type': 'symlink',
'opt': variable,
},
ip.xmlfiles,
) )
family.variable = [] if ip.netmask:
if hasattr(elt, 'disabled'): self.objectspace.add_variable(path,
disabled = elt.disabled f'{path}.netmask',
else: 'netmask',
disabled = False {'type': 'symlink',
activate_obj = self._generate_element('boolean', 'opt': self.objectspace.paths[ip.netmask],
None, },
None, ip.xmlfiles,
'activate',
not disabled,
elt,
subpath,
path_prefix,
)
for key in dir(elt):
if key.startswith('_') or key.endswith('_type') or key in ERASED_ATTRIBUTES2:
continue
value = getattr(elt, key)
if key in [listname, 'servicelist']:
self.objectspace.paths.list_conditions[path_prefix].setdefault(key,
{}).setdefault(
value,
[]).append(activate_obj)
continue
if key == 'name':
dtd_key_type = elttype + '_type'
else:
dtd_key_type = key + '_type'
elt_type = getattr(elt, dtd_key_type, None)
if elt_type:
try:
value = CONVERT_OPTION.get(elt_type, {}).get('func', str)(value)
except ValueError as err:
msg = _(f'"{value}" is not a valid "{elttype}": {err}')
raise DictConsistencyError(msg, 93, elt.xmlfiles)
if key not in FORCE_INFORMATIONS and elt_type:
if elt_type == 'variable':
elt_type = 'symlink'
family.variable.append(self._generate_element(elt_type,
dtd_key_type,
elttype,
key,
value,
elt,
subpath,
path_prefix,
))
else:
setattr(family.information, key, value)
family.variable.append(activate_obj)
families.append(family)
return families
def _get_name_path(self,
elt,
path: str,
root_path: str,
path_prefix: str,
) -> Tuple[str, str]:
# create element name, if already exists, add _xx to be uniq
if hasattr(elt, 'source') and elt.source:
name = elt.source
else:
name = elt.name
idx = 0
while True:
c_name = name
if idx:
c_name += f'_{idx}'
subpath = '{}.{}'.format(path, normalize_family(c_name))
try:
self.objectspace.paths.get_family(subpath, root_path, path_prefix)
except DictConsistencyError as err:
if err.errno == 42:
return c_name, subpath
idx += 1
def _gen_family(self,
name,
subpath,
xmlfiles,
path_prefix,
with_informations=True,
):
family = self.objectspace.family(xmlfiles)
family.name = normalize_family(name)
family.doc = name
family.mode = None
self.objectspace.paths.add_family('services',
subpath,
family,
False,
force_path_prefix=path_prefix,
) )
if with_informations: self._generate_element('boolean',
family.information = self.objectspace.information(xmlfiles) None,
return family None,
'activate',
True,
#not service.disabled,
ip,
path,
path_prefix,
)
def convert_service_certificates(self,
certificate: dict,
subpath: str,
service_name: str,
path_prefix: str,
) -> None:
if isinstance(certificate.name, dict):
variable = self.objectspace.paths[certificate.name['name']]
if variable.type != 'filename':
msg = _(f'certificate cannot be linked to "{variable.type}" variable "{ip.name}"')
raise Exception(msg)
# raise DictConsistencyError(msg, 70, ip.xmlfiles)
name_obj = {'type': 'symlink',
'opt': variable,
}
else:
name = certificate.name
name_obj = {'default': name}
name = normalize_family(name)
path = f'{subpath}.{name}'
self.objectspace.add_family(subpath,
path,
name,
{'doc': name},
certificate.xmlfiles,
)
self.objectspace.add_variable(path,
f'{path}.name',
'name',
name_obj,
certificate.xmlfiles,
)
self.objectspace.informations.add(path, 'authority', certificate.authority)
for typ in ['provider', 'format', 'type']:
value = getattr(certificate, typ)
if value:
self.objectspace.informations.add(path, typ, value)
if certificate.mode:
PermissionsOption('', '', default=certificate.mode)
self.objectspace.informations.add(path, 'mode', certificate.mode)
#
for typ in ['owner', 'group']:
value = getattr(certificate, typ)
if value is None:
continue
if isinstance(value, str):
UsernameOption('', '', default=value)
new_variable = {'type': 'unix_user',
'default': value}
else:
new_variable = {'type': 'symlink',
'opt': self.objectspace.paths[value['name']],
}
self.objectspace.add_variable(path,
f'{path}.{typ}',
typ,
new_variable,
certificate.xmlfiles,
)
#
if certificate.domain is None:
certificate.domain = self.objectspace.rougailconfig['default_certificate_domain']
for typ in ['server', 'domain']:
value = getattr(certificate, typ)
if value is None:
continue
value = {'type': 'symlink',
'opt': self.objectspace.paths[value],
}
self.objectspace.add_variable(path,
f'{path}.{typ}',
typ,
value,
certificate.xmlfiles,
)
self._generate_element('boolean',
None,
None,
'activate',
True,
#not service.disabled,
certificate,
path,
path_prefix,
)
def convert_service_files(self,
file: dict,
subpath: str,
service_name: str,
path_prefix: str,
) -> None:
if isinstance(file.source, dict):
if file.source['type'] != 'variable':
raise Exception('pfff')
source_obj = {'type': 'symlink',
'opt': self.objectspace.paths[file.source['name']],
}
else:
source_obj = {'type': 'filename',
'default': file.name,
}
if not file.variable:
if not file.source:
file.source = basename(file.name)
elif not file.source:
msg = _(f'attribute "source" is mandatory for the file "{file.name}" in '
f'"({service_name})"')
raise DictConsistencyError(msg, 34, file_.xmlfiles)
name, path = self.get_name_path(file, subpath)
self.objectspace.add_family(subpath,
path,
name,
{'doc': name},
file.xmlfiles,
)
self.objectspace.add_variable(path,
f'{path}.name',
'name',
{'type': 'filename',
'default': file.name,
},
file.xmlfiles,
)
#
self.objectspace.add_variable(path,
f'{path}.source',
'source',
source_obj,
file.xmlfiles,
)
#
if file.mode:
PermissionsOption('', '', default=file.mode)
self.objectspace.informations.add(path, 'mode', file.mode)
#
if file.engine:
self.objectspace.informations.add(path, 'engine', file.engine)
#
if file.included != 'no':
self.objectspace.informations.add(path, 'included', file.included)
#
for typ in ['owner', 'group']:
value = getattr(file, typ)
if value is None:
continue
if isinstance(value, str):
UsernameOption('', '', default=value)
new_variable = {'type': 'unix_user',
'default': value}
else:
new_variable = {'type': 'symlink',
'opt': self.objectspace.paths[value['name']],
}
self.objectspace.add_variable(path,
f'{path}.{typ}',
typ,
new_variable,
file.xmlfiles,
)
#
self._generate_element('boolean',
None,
None,
'activate',
True,
#not service.disabled,
file,
path,
path_prefix,
)
def convert_service_overrides(self,
override: dict,
subpath: str,
service_name: str,
path_prefix: str,
) -> None:
name, path = self.get_name_path(override, subpath)
self.objectspace.add_family(subpath,
path,
name,
{'doc': name},
override.xmlfiles,
)
self.objectspace.add_variable(path,
f'{path}.name',
'name',
{'type': 'filename',
'default': override.name,
},
override.xmlfiles,
)
#
if override.source:
self.objectspace.add_variable(path,
f'{path}.source',
'source',
{'type': 'filename',
'default': override.source,
},
override.xmlfiles,
)
#
#
if override.engine:
self.objectspace.informations.add(path, 'engine', override.engine)
#
self._generate_element('boolean',
None,
None,
'activate',
True,
#not service.disabled,
override,
path,
path_prefix,
)
def _generate_element(self, def _generate_element(self,
type_, type_,
@ -303,13 +432,13 @@ class Annotator:
key, key,
value, value,
elt, elt,
path, subpath,
path_prefix, path_prefix,
): # pylint: disable=R0913 ): # pylint: disable=R0913
variable = self.objectspace.variable(elt.xmlfiles) name = normalize_family(key)
variable.name = normalize_family(key) variable_obj = {'type': type_,
variable.mode = None 'xmlfiles': elt.xmlfiles
variable.type = type_ }
if type_ == 'symlink': if type_ == 'symlink':
variable.opt = self.objectspace.paths.get_variable(value, variable.opt = self.objectspace.paths.get_variable(value,
self.objectspace.rougailconfig['variable_namespace'], self.objectspace.rougailconfig['variable_namespace'],
@ -325,15 +454,21 @@ class Annotator:
raise DictConsistencyError(msg, 58, elt.xmlfiles) raise DictConsistencyError(msg, 58, elt.xmlfiles)
else: else:
variable.doc = key variable_obj['description'] = key
variable.default = value variable_obj['default'] = value
variable.namespace = 'services' path = f'{subpath}.{name}'
self.objectspace.paths.add_variable('services', self.objectspace.add_variable(subpath,
path, path,
variable, name,
force_path_prefix=path_prefix variable_obj,
) elt.xmlfiles,
return variable )
# self.objectspace.paths.add_variable('services',
# path,
# variable,
# force_path_prefix=path_prefix
# )
return self.objectspace.paths[path]
def _update_override(self, def _update_override(self,
override, override,
@ -363,37 +498,6 @@ class Annotator:
f'"({service_name})"') f'"({service_name})"')
raise DictConsistencyError(msg, 34, file_.xmlfiles) raise DictConsistencyError(msg, 34, file_.xmlfiles)
def _update_ip(self,
ip,
service_name,
path_prefix,
) -> None:
variable = self.objectspace.paths.get_variable(ip.name,
ip.namespace,
xmlfiles=ip.xmlfiles,
force_path_prefix=path_prefix,
add_path_prefix=True,
)
if variable.type not in ['ip', 'network', 'network_cidr']:
msg = _(f'ip cannot be linked to "{variable.type}" variable "{ip.name}"')
raise DictConsistencyError(msg, 70, ip.xmlfiles)
if variable.type in ['ip', 'network_cidr'] and hasattr(ip, 'netmask'):
msg = _(f'ip with ip_type "{variable.type}" must not have netmask')
raise DictConsistencyError(msg, 59, ip.xmlfiles)
if variable.type == 'network' and not hasattr(ip, 'netmask'):
msg = _(f'ip with ip_type "{variable.type}" must have netmask')
raise DictConsistencyError(msg, 64, ip.xmlfiles)
if hasattr(ip, 'netmask'):
netmask = self.objectspace.paths.get_variable(ip.netmask,
ip.namespace,
xmlfiles=ip.xmlfiles,
force_path_prefix=path_prefix,
add_path_prefix=True,
)
if netmask.type != 'netmask':
msg = _(f'netmask in ip must have type "netmask", not "{netmask.type}"')
raise DictConsistencyError(msg, 65, ip.xmlfiles)
def _update_certificate(self, def _update_certificate(self,
certificate, certificate,
certificate_name, certificate_name,
@ -418,3 +522,25 @@ class Annotator:
if variable.type != 'domainname': if variable.type != 'domainname':
msg = _(f'the certificate "{certificate.name}" has an attribute "domain" linked with a "{variable.type}" variable ("{certificate.domain}"), but must be a "domainename" variable') msg = _(f'the certificate "{certificate.name}" has an attribute "domain" linked with a "{variable.type}" variable ("{certificate.domain}"), but must be a "domainename" variable')
raise DictConsistencyError(msg, 94, certificate.xmlfiles) raise DictConsistencyError(msg, 94, certificate.xmlfiles)
def get_name_path(self,
elt,
subpath: str,
) -> Tuple[str, str]:
# create element name, if already exists, add _xx to be uniq
if hasattr(elt, 'source') and elt.source:
name = elt.source
if isinstance(name, dict):
name = name['name']
else:
name = elt.name
name = normalize_family(name)
idx = 0
while True:
c_name = name
if idx:
c_name += f'_{idx}'
path = f'{subpath}.{c_name}'
if path not in self.objectspace.families:
return c_name, path
idx += 1

View file

@ -31,6 +31,8 @@ from rougail.annotator.variable import Walk
from rougail.i18n import _ from rougail.i18n import _
from rougail.error import DictConsistencyError from rougail.error import DictConsistencyError
from rougail.annotator.fill import get_jinja_variable_to_param
class Annotator(Walk): # pylint: disable=R0903 class Annotator(Walk): # pylint: disable=R0903
"""Annotate value """Annotate value
@ -38,10 +40,12 @@ class Annotator(Walk): # pylint: disable=R0903
level = 70 level = 70
def __init__(self, def __init__(self,
objectspace, objectspace,
functions,
*args, *args,
) -> None: ) -> None:
if not hasattr(objectspace.space, 'variables'): if not objectspace.paths:
return return
self.functions = functions
self.objectspace = objectspace self.objectspace = objectspace
self.convert_value() self.convert_value()
self.add_choice_nil() self.add_choice_nil()
@ -50,52 +54,79 @@ class Annotator(Walk): # pylint: disable=R0903
"""convert value """convert value
""" """
for variable in self.get_variables(): for variable in self.get_variables():
if variable.type == 'symlink':
continue
self._convert_value(variable) self._convert_value(variable)
def _convert_value(self, def _convert_value(self,
variable, variable: dict,
) -> None: ) -> None:
multi = self.objectspace.multis.get(variable.path, False)
# a boolean must have value, the default value is "True" # a boolean must have value, the default value is "True"
if not hasattr(variable, 'value') and variable.type == 'boolean': if variable.type == 'boolean' and \
new_value = self.objectspace.value(variable.xmlfiles) multi is False and \
new_value.name = True variable.default is None:
new_value.type = 'boolean' variable.default = True
variable.value = [new_value]
# if the variable is mandatory and doesn't have any value if variable.default is None:
# then the variable's mode is set to 'basic'
# variable with default value is mandatory
if hasattr(variable, 'value') and variable.value:
has_value = True
for value in variable.value:
if value.type == 'calculation' or value.type == 'nil':
has_value = False
break
if has_value and 'mandatory' not in vars(variable):
# if has value without any calculation
variable.mandatory = True
if not hasattr(variable, 'value'):
return return
if variable.value[0].type == 'calculation':
variable.default = variable.value[0] has_value = False
elif variable.multi: if isinstance(variable.default, dict):
if self.objectspace.paths.is_follower(variable): if variable.default['type'] == 'jinja':
if variable.multi != 'submulti' and len(variable.value) != 1: path_prefix = None
default = {'type': 'jinja',
'jinja': variable.default['jinja'],
'params': {'__internal_jinja': variable.path,
'__internal_type': variable.type,
'__internal_multi': multi,
},
}
for sub_variable in get_jinja_variable_to_param(variable.default['jinja'],
self.objectspace,
variable.xmlfiles,
path_prefix,
self.functions,
None,
None,
):
if isinstance(sub_variable, self.objectspace.variable):
default['params'][sub_variable.path] = sub_variable
elif sub_variable == '__suffix':
default['params'][sub_variable] = self.objectspace.param(type='suffix')
elif sub_variable == '__index':
default['params'][sub_variable] = self.objectspace.param(type='index')
else:
default['params'][sub_variable] = sub_variable
variable.default = default
else:
raise Exception('pfff')
elif isinstance(variable.default, list):
if not multi:
raise Exception('pfff')
if variable.path in self.objectspace.followers:
if multi != 'submulti' and len(variable.default) != 1:
msg = _(f'the follower "{variable.name}" without multi attribute can only have one value') msg = _(f'the follower "{variable.name}" without multi attribute can only have one value')
raise DictConsistencyError(msg, 87, variable.xmlfiles) raise DictConsistencyError(msg, 87, variable.xmlfiles)
else: # else:
variable.default = [value.name for value in variable.value] # variable.default = [value.name for value in variable.default]
if not self.objectspace.paths.is_leader(variable): if variable.path not in self.objectspace.leaders:
if variable.multi == 'submulti': if multi == 'submulti':
variable.default_multi = [value.name for value in variable.value] self.objectspace.default_multi[variable.path] = variable.default #[value.name for value in variable.value]
else: else:
variable.default_multi = variable.value[0].name self.objectspace.default_multi[variable.path] = variable.default[0] #.name
has_value = True
elif variable.multi:
#msg = _(f'the none multi variable "{variable.name}" cannot have '
# 'more than one value')
#raise DictConsistencyError(msg, 68, variable.xmlfiles)
raise Exception('pfff')
else: else:
if len(variable.value) > 1: has_value = True
msg = _(f'the none multi variable "{variable.name}" cannot have ' # variable with default value is mandatory
'more than one value') if has_value and variable.mandatory is None:
raise DictConsistencyError(msg, 68, variable.xmlfiles) # if has value without any calculation
variable.default = variable.value[0].name variable.mandatory = True
del variable.value
def add_choice_nil(self) -> None: def add_choice_nil(self) -> None:
"""A variable with type "Choice" that is not mandatory must has "nil" value """A variable with type "Choice" that is not mandatory must has "nil" value
@ -104,11 +135,9 @@ class Annotator(Walk): # pylint: disable=R0903
if variable.type != 'choice': if variable.type != 'choice':
continue continue
is_none = False is_none = False
for choice in variable.choice: for choice in variable.choices:
if choice.type == 'nil': if choice is None:
is_none = True is_none = True
break
if not variable.mandatory and not is_none: if not variable.mandatory and not is_none:
choice = self.objectspace.choice(variable.xmlfiles) variable.choices.append(None)
choice.name = None
choice.type = 'nil'
variable.choice.append(choice)

View file

@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from rougail.i18n import _ from rougail.i18n import _
from rougail.error import DictConsistencyError from rougail.error import DictConsistencyError
from rougail.objspace import convert_boolean, get_variables from rougail.objspace import convert_boolean #, get_variables
CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int), CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
@ -75,56 +75,58 @@ class Walk:
def get_variables(self): def get_variables(self):
"""Iter all variables from the objectspace """Iter all variables from the objectspace
""" """
yield from get_variables(self.objectspace) for path in self.objectspace.variables:
yield self.objectspace.paths[path]
# yield from get_variables(self.objectspace)
def get_families(self, def get_families(self):
with_parent: bool=False,
):
"""Iter all families from the objectspace """Iter all families from the objectspace
""" """
for family in self.objectspace.space.variables.values(): for path in self.objectspace.families:
yield from self._get_families(family, None, with_parent) yield self.objectspace.paths[path]
# for family in self.objectspace.space.variables.values():
def _get_families(self, # yield from self._get_families(family, None, with_parent)
family: 'self.objectspace.family', #
old_family: 'self.objectspace.family', # def _get_families(self,
with_parent: bool, # family: 'self.objectspace.family',
): # old_family: 'self.objectspace.family',
if with_parent: # with_parent: bool,
yield family, old_family, # ):
if hasattr(family, 'variable'): # if with_parent:
if not with_parent: # yield family, old_family,
yield family # if hasattr(family, 'variable'):
for fam in family.variable.values(): # if not with_parent:
if isinstance(fam, self.objectspace.family): # yield family
yield from self._get_families(fam, family, with_parent) # for fam in family.variable.values():
if hasattr(family, 'variables'): # if isinstance(fam, self.objectspace.family):
for fam in family.variables.values(): # yield from self._get_families(fam, family, with_parent)
yield from self._get_families(fam, family, with_parent) # if hasattr(family, 'variables'):
# for fam in family.variables.values():
def get_constraints(self, # yield from self._get_families(fam, family, with_parent)
create: bool=False, #
path_prefix: str=None, # def get_constraints(self,
): # create: bool=False,
if not self.objectspace.paths.has_path_prefix(): # path_prefix: str=None,
if hasattr(self.objectspace.space, 'constraints'): # ):
yield None, self.objectspace.space.constraints # if not self.objectspace.paths.has_path_prefix():
elif create: # if hasattr(self.objectspace.space, 'constraints'):
self.objectspace.space.constraints = self.objectspace.constraints(None) # yield None, self.objectspace.space.constraints
yield None, self.objectspace.space.constraints # elif create:
else: # self.objectspace.space.constraints = self.objectspace.constraints(None)
if path_prefix: # yield None, self.objectspace.space.constraints
path_prefixes = [path_prefix] # else:
else: # if path_prefix:
path_prefixes = self.objectspace.paths.get_path_prefixes() # path_prefixes = [path_prefix]
for path_prefix in path_prefixes: # else:
if hasattr(self.objectspace.space, 'variables') and \ # path_prefixes = self.objectspace.paths.get_path_prefixes()
path_prefix in self.objectspace.space.variables and \ # for path_prefix in path_prefixes:
hasattr(self.objectspace.space.variables[path_prefix], 'constraints'): # if hasattr(self.objectspace.space, 'variables') and \
yield path_prefix, self.objectspace.space.variables[path_prefix].constraints # path_prefix in self.objectspace.space.variables and \
elif create: # hasattr(self.objectspace.space.variables[path_prefix], 'constraints'):
self.objectspace.space.variables[path_prefix].constraints = self.objectspace.constraints(None) # yield path_prefix, self.objectspace.space.variables[path_prefix].constraints
yield path_prefix, self.objectspace.space.variables[path_prefix].constraints # elif create:
# self.objectspace.space.variables[path_prefix].constraints = self.objectspace.constraints(None)
# yield path_prefix, self.objectspace.space.variables[path_prefix].constraints
class Annotator(Walk): # pylint: disable=R0903 class Annotator(Walk): # pylint: disable=R0903
@ -135,7 +137,7 @@ class Annotator(Walk): # pylint: disable=R0903
objectspace, objectspace,
*args, *args,
): ):
if not hasattr(objectspace.space, 'variables'): if not objectspace.paths:
return return
self.objectspace = objectspace self.objectspace = objectspace
self.forbidden_name = ['services', self.objectspace.rougailconfig['variable_namespace']] self.forbidden_name = ['services', self.objectspace.rougailconfig['variable_namespace']]
@ -149,83 +151,107 @@ class Annotator(Walk): # pylint: disable=R0903
"""convert variable """convert variable
""" """
for variable in self.get_variables(): for variable in self.get_variables():
if variable.type == 'symlink':
continue
self._convert_variable(variable) self._convert_variable(variable)
def _convert_variable(self, def _convert_variable(self,
variable, variable: dict,
) -> None: ) -> None:
if variable.namespace == self.objectspace.rougailconfig['variable_namespace'] and \ # variable without description: description is the name
variable.name in self.forbidden_name: if not variable.description:
msg = _(f'the name of the variable "{variable.name}" cannot be the same as the name'
' of a namespace')
raise DictConsistencyError(msg, 54, variable.xmlfiles)
if variable.type != 'symlink' and not hasattr(variable, 'description'):
variable.description = variable.name variable.description = variable.name
if hasattr(variable, 'value'): if variable.path in self.objectspace.followers:
for idx, value in enumerate(variable.value): if not variable.multi:
if not hasattr(value, 'name') and not hasattr(value, 'type'): self.objectspace.multis[variable.path] = True
msg = f'variable "{variable.name}" has a value without text, if you want the value None, set value type to nil' else:
raise DictConsistencyError(msg, 95, value.xmlfiles) self.objectspace.multis[variable.path] = 'submulti'
if not hasattr(value, 'type'): if self.objectspace.paths[variable.path.rsplit('.', 1)[0]].hidden:
value.type = variable.type self.objectspace.properties.append(variable.path, 'frozen')
if hasattr(value, 'name'): self.objectspace.properties.append(variable.path, 'force_default_on_freeze')
try: elif variable.multi:
value.name = CONVERT_OPTION.get(value.type, {}).get('func', str)(value.name) self.objectspace.multis[variable.path] = True
except Exception as err: if variable.path in self.objectspace.leaders:
msg = _(f'the variable "{variable.name}" has an incorrect value "{value.name}" with "{variable.type}" type') if not self.objectspace.multis.get(variable.path, False):
raise DictConsistencyError(msg, 88, variable.xmlfiles) msg = _(f'the variable "{variable.name}" in a leadership must be multi')
else: raise DictConsistencyError(msg, 32, variable.xmlfiles)
value.name = None family = self.objectspace.paths[variable.path.rsplit('.', 1)[0]]
if not variable.value: if variable.hidden:
del variable.value family.hidden = variable.hidden
if hasattr(variable, 'choice'): elif family.hidden:
variable.hidden = family.hidden
if variable.hidden:
self.objectspace.properties.append(variable.path, 'frozen')
self.objectspace.properties.append(variable.path, 'force_default_on_freeze')
variable.hidden = None
#for idx, value in enumerate(variable.default):
# if not hasattr(value, 'name') and not hasattr(value, 'type'):
# msg = f'variable "{variable.name}" has a value without text, if you want the value None, set value type to nil'
# raise DictConsistencyError(msg, 95, value.xmlfiles)
# if not hasattr(value, 'type'):
# value.type = variable.type
# if hasattr(value, 'name'):
# try:
# value.name = CONVERT_OPTION.get(value.type, {}).get('func', str)(value.name)
# except Exception as err:
# msg = _(f'the variable "{variable.name}" has an incorrect value "{value.name}" with "{variable.type}" type')
# raise DictConsistencyError(msg, 88, variable.xmlfiles)
# else:
# value.name = None
#if not variable.value:
# del variable.value
if variable.choices is not None:
if variable.type != 'choice': if variable.type != 'choice':
msg = _(f'choice for the variable "{variable.name}" not allowed with "{variable.type}" type') msg = _(f'choice for the variable "{variable.name}" not allowed with "{variable.type}" type')
raise DictConsistencyError(msg, 3, variable.xmlfiles) raise DictConsistencyError(msg, 3, variable.xmlfiles)
values = [] values = []
choice_type = None choice_type = None
for choice in variable.choice: for choice in variable.choices:
if choice_type == 'variable': #if choice_type == 'variable':
msg = _(f'only one "variable" choice is allowed ' # msg = _(f'only one "variable" choice is allowed '
f'the variable "{variable.name}"') # f'the variable "{variable.name}"')
raise DictConsistencyError(msg, 5, choice.xmlfiles) # raise DictConsistencyError(msg, 5, choice.xmlfiles)
if choice.type == 'nil': #if choice.type == 'nil':
choice.name = None # choice.name = None
elif choice.type == 'space': #elif choice.type == 'space':
choice.name = ' ' # choice.name = ' '
elif choice.type == 'variable': if isinstance(choice, dict):
choice.name = self.objectspace.paths.get_variable(choice.name, if choice['type'] == 'variable':
variable.namespace, obj = self.objectspace.paths[choice['variable']]
force_path_prefix=variable.path_prefix, #FIXME?
) if not obj.multi:
if not choice.name.multi: msg = _(f'only multi "variable" is allowed for a choice '
msg = _(f'only multi "variable" is allowed for a choice ' f'of variable "{variable.name}"')
f'of variable "{variable.name}"') raise DictConsistencyError(msg, 6, choice['xmlfiles'])
raise DictConsistencyError(msg, 6, choice.xmlfiles) #values.append(obj)
else: choice['variable'] = obj
if not hasattr(choice, 'name'): elif choice['type'] != 'jinja':
msg = _(f'choice for variable "{variable.name}" must have a value') raise Exception('hu?')
raise DictConsistencyError(msg, 14, choice.xmlfiles) # else:
choice.name = CONVERT_OPTION.get(choice.type, {}).get('func', str)(choice.name) # if not hasattr(choice, 'name'):
if choice_type is None: # msg = _(f'choice for variable "{variable.name}" must have a value')
choice_type = choice.type # raise DictConsistencyError(msg, 14, choice.xmlfiles)
values.append(choice.name) # choice.name = CONVERT_OPTION.get(choice.type, {}).get('func', str)(choice.name)
if choice_type not in ['function', 'variable'] and hasattr(variable, 'value'): #if choice_type is None:
for value in variable.value: # choice_type = choice.type
if value.name not in values: # else:
msg = _(f'value "{value.name}" of variable "{variable.name}" is not in list ' # values.append(choice)
f'of all expected values ({values})') # FIXME if variable.values:
raise DictConsistencyError(msg, 15, value.xmlfiles) # FIXME for value in variable.values:
ref_choice = variable.choice[0] # FIXME if value not in values:
self.objectspace.paths.set_valid_enums(variable.path, # FIXME msg = _(f'value "{value.name}" of variable "{variable.name}" is not in list '
values, # FIXME f'of all expected values ({values})')
variable.path_prefix, # FIXME raise DictConsistencyError(msg, 15, value.xmlfiles)
) #ref_choice = variable.choices[0]
self.objectspace.choices.append(variable.path,
values,
)
elif variable.type == 'choice': elif variable.type == 'choice':
msg = _(f'choice is mandatory for the variable "{variable.name}" with choice type') msg = _(f'choice is mandatory for the variable "{variable.name}" with choice type')
raise DictConsistencyError(msg, 4, variable.xmlfiles) raise DictConsistencyError(msg, 4, variable.xmlfiles)
variable.doc = variable.description # variable.doc = variable.description
del variable.description # del variable.description
def convert_test(self): def convert_test(self):
"""Convert variable tests value """Convert variable tests value
@ -241,17 +267,13 @@ class Annotator(Walk): # pylint: disable=R0903
else: else:
value = CONVERT_OPTION.get(variable.type, {}).get('func', str)(value) value = CONVERT_OPTION.get(variable.type, {}).get('func', str)(value)
new_values.append(value) new_values.append(value)
if not hasattr(variable, 'information'): self.objectspace.informations.add(variable.path, 'test', tuple(new_values))
variable.information = self.objectspace.information(variable.xmlfiles)
variable.information.test = tuple(new_values)
def convert_help(self): def convert_help(self):
"""Convert variable help """Convert variable help
""" """
for variable in self.get_variables(): for variable in self.get_variables():
if not hasattr(variable, 'help'): if not hasattr(variable, 'help') or not variable.help:
continue continue
if not hasattr(variable, 'information'): self.objectspace.informations.add(variable.path, 'help', variable.help)
variable.information = self.objectspace.information(variable.xmlfiles)
variable.information.help = variable.help
del variable.help del variable.help

View file

@ -36,6 +36,7 @@ DTDDIR = join(dirname(abspath(__file__)), 'data')
RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')], RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
'services_dir': [join(ROUGAILROOT, 'services')],
'extra_dictionaries': {}, 'extra_dictionaries': {},
'patches_dir': join(ROUGAILROOT, 'patches'), 'patches_dir': join(ROUGAILROOT, 'patches'),
'templates_dir': join(ROUGAILROOT, 'templates'), 'templates_dir': join(ROUGAILROOT, 'templates'),
@ -62,14 +63,14 @@ RougailConfig = {'dictionaries_dir': [join(ROUGAILROOT, 'dictionaries')],
'modes_level': ['basic', 'normal', 'expert'], 'modes_level': ['basic', 'normal', 'expert'],
'default_family_mode': 'basic', 'default_family_mode': 'basic',
'default_variable_mode': 'normal', 'default_variable_mode': 'normal',
'default_files_engine': 'cheetah', 'default_files_engine': 'jinja',
'default_files_mode': 644, 'default_files_mode': 644,
'default_files_owner': 'root', 'default_files_owner': 'root',
'default_files_group': 'root', 'default_files_group': 'root',
'default_files_included': 'no', 'default_files_included': 'no',
'default_overrides_engine': 'cheetah', 'default_overrides_engine': 'jinja',
'default_service_names_engine': 'none', 'default_service_names_engine': 'none',
'default_certificate_domain': 'server_name', 'default_certificate_domain': 'rougail.server_name',
'base_option_name': 'baseoption', 'base_option_name': 'baseoption',
'export_with_import': True, 'export_with_import': True,
'force_convert_dyn_option_description': False, 'force_convert_dyn_option_description': False,

View file

@ -54,7 +54,7 @@ from .reflector import Reflector
from .tiramisureflector import TiramisuReflector from .tiramisureflector import TiramisuReflector
from .annotator import SpaceAnnotator from .annotator import SpaceAnnotator
from .error import DictConsistencyError from .error import DictConsistencyError
from .providersupplier import provider_supplier #from .providersupplier import provider_supplier
from .utils import normalize_family from .utils import normalize_family
@ -97,10 +97,10 @@ class RougailConvert:
extra_dir, extra_dir,
path_prefix, path_prefix,
) )
if hasattr(self.rougailobjspace.space, 'variables'): # if hasattr(self.rougailobjspace.space, 'variables'):
provider_supplier(self.rougailobjspace, # provider_supplier(self.rougailobjspace,
path_prefix, # path_prefix,
) # )
self.dictionaries = True self.dictionaries = True
def _load_dictionaries(self, def _load_dictionaries(self,

653
src/rougail/new_test.py Normal file
View file

@ -0,0 +1,653 @@
from typing import Optional, Union, get_type_hints, Any, Literal, List, Dict
from pydantic import BaseModel
from yaml import safe_load
from os import listdir
from os.path import join, isdir
from .annotator import SpaceAnnotator
from .tiramisureflector import TiramisuReflector
from .utils import normalize_family
class Family(BaseModel):
name: str
description: Optional[str]=None
type: Literal['family', 'leadership', 'dynamic']='family'
help: Optional[str]=None
mode: Optional[str]=None
hidden: Union[bool, str]=False
disabled: Union[bool, str]=False
xmlfiles: List[str]=[]
path: str
class Dynamic(Family):
variable: str
class Variable(BaseModel):
name: str
type: Literal['number', 'float', 'string', 'password', 'secret', 'mail', 'boolean', 'filename', 'date', 'unix_user', 'ip', 'local_ip', 'netmask', 'network', 'broadcast', 'netbios', 'domainname', 'hostname', 'web_address', 'port', 'mac', 'cidr', 'network_cidr', 'choice', 'unix_permissions']='string'
description: Optional[str]=None
default: Any=None
choices: Any=None
validators: Any=None
multi: bool=False
unique: Optional[bool]=None
help: Optional[str]=None
hidden: Union[bool, str]=False
disabled: Union[bool, str]=False
mandatory: Union[None, bool, str]=None
auto_save: bool=False
mode: Optional[str]=None
provider: Optional[str]=None
supplier: Optional[str]=None
test: Any=None
xmlfiles: List[str]=[]
path: str
class SymLink(BaseModel):
name: str
type: str='symlink'
opt: Variable
xmlfiles: List[str]=[]
path: str
class Service(BaseModel):
name: str
manage: bool=True
type: Literal['service', 'mount', 'swap', 'timer', 'target']='service'
disabled: Union[bool, str]=False
engine: Optional[str]=None
target: Optional[str]=None
undisable: bool=False
xmlfiles: List[str]=[]
class IP(BaseModel):
name: str
netmask: Optional[str]=None
disabled: Union[bool, str]=False
xmlfiles: List[str]=[]
class Certificate(BaseModel):
name: str
authority: str
mode: Optional[int]=None
owner: Union[None, str, Dict[str, str]]=None
group: Union[None, str, Dict[str, str]]=None
server: Union[None, str, Dict[str, str]]=None
domain: Union[None, str, Dict[str, str]]=None
provider: Optional[str]=None
format: Literal['cert_key', 'pem']='cert_key'
type: Literal['client', 'server']='client'
disabled: Union[bool, str]=False
xmlfiles: List[str]=[]
class File(BaseModel):
name: str
type: Literal['string', 'variable']='string'
mode: Optional[int]=None
owner: Union[None, str, Dict[str, str]]=None
group: Union[None, str, Dict[str, str]]=None
source: Union[None, str, Dict[str, str]]=None
engine: Optional[str]=None
variable: Optional[str]=None
included: Literal['no', 'name', 'content']='no'
disabled: Union[bool, str]=False
xmlfiles: List[str]=[]
class Override(BaseModel):
name: str
type: Literal['string', 'variable']='string'
source: Optional[str]=None
engine: Optional[str]=None
xmlfiles: List[str]=[]
class Param(BaseModel):
type: str
class Appendable:
def __init__(self) -> None:
self._data = {}
def append(self,
path: str,
data: str,
) -> None:
if path not in self._data:
self._data[path] = []
self._data[path].append(data)
def __getitem__(self,
path: str,
) -> list:
return self._data.get(path, [])
def __contains__(self,
path: str,
) -> bool:
return path in self._data
class Paths:
def __init__(self) -> None:
self._data = {}
def add(self,
path: str,
data: str,
force: bool=False,
) -> None:
if not force and path in self._data:
raise Exception('pfff')
self._data[path] = data
def __getitem__(self,
path: str,
) -> dict:
if not path in self._data:
raise Exception(f'cannot find variable or family {path}')
return self._data[path]
def __contains__(self,
path: str,
) -> bool:
return path in self._data
def __delitem__(self,
path: str,
) -> None:
del self._data[path]
def get(self):
return self._data.values()
class Informations:
def __init__(self) -> None:
self._data = {}
def add(self,
path: str,
key: str,
data: Any,
) -> None:
if data is None:
raise Exception('connard')
if path not in self._data:
self._data[path] = {}
if key in self._data[path]:
raise Exception(f'already key {key} in {path}')
self._data[path][key] = data
def get(self,
path: str,
) -> List[str]:
return self._data.get(path, [])
class ParserVariable:
def __init__(self):
self.paths = Paths()
self.families = []
self.variables = []
self.parents = {'.': []}
self.index = 0
self.reflector_names = {}
self.leaders = []
self.followers = []
self.dynamics = []
self.multis = {}
#
self.family = Family
self.dynamic = Dynamic
self.variable = Variable
self.param = Param
#FIXME
self.exclude_imports = []
self.informations = Informations()
self.properties = Appendable()
self.choices = Appendable()
self.default_multi = {}
super().__init__()
def load(self):
hint_family = get_type_hints(self.dynamic)
self.family_types = hint_family['type'].__args__
self.family_attrs = frozenset(set(hint_family) | {'redefine'} - {'name', 'path', 'xmlfiles'})
hint_variable = get_type_hints(self.variable)
self.variable_types = hint_variable['type'].__args__
self.variable_attrs = frozenset(set(hint_variable) | {'redefine', 'exists'} - {'name', 'path', 'xmlfiles'})
super().load()
def parse_variable_file(self,
filename: str,
namespace: str,
# description: str,
) -> None:
with open(filename) as o:
objects = safe_load(o)
self.validate_file_version(objects)
self.parse_family(filename, namespace, '.', namespace, {})
for name, obj in objects.items():
self.family_or_variable(filename,
name,
namespace,
obj,
)
def family_or_variable(self,
filename: str,
name: str,
subpath: str,
obj: dict,
first_variable: bool=False,
family_is_leadership: bool=False,
family_is_dynamic: bool=False,
) -> None:
if subpath:
path = f'{subpath}.{name}'
else:
path = name
if 'type' in obj:
if obj['type'] in self.family_types:
typ = 'family'
elif obj['type'] in self.variable_types:
typ = 'variable'
else:
raise Exception('hu.')
else:
if path in self.paths:
if path in self.families:
typ = 'family'
else:
typ = 'variable'
else:
extra_keys = set(obj) - self.family_attrs
typ = 'family'
for key in extra_keys:
value = obj[key]
if not isinstance(value, dict):
typ = 'variable'
break
if typ == 'variable' and set(obj) - self.variable_attrs:
raise Exception('cannot found type of {obj}')
if typ == 'family':
parser = self.parse_family
else:
parser = self.parse_variable
parser(filename,
name,
subpath,
path,
obj,
first_variable,
family_is_leadership,
family_is_dynamic,
)
def parse_family(self,
filename: str,
name: str,
subpath: str,
path: str,
family: dict,
first_variable: bool=False,
family_is_leadership: bool=False,
family_is_dynamic: bool=False,
) -> None:
family_obj = {}
subfamily_obj = {}
for key, value in family.items():
if key.startswith('_'):
key = key[1:]
if key in self.family_attrs and not isinstance(value, dict):
family_obj[key] = value
else:
subfamily_obj[key] = value
if path in self.paths:
if family_obj:
if not family.pop('redefine', False):
raise Exception('pfff')
self.paths.add(path, self.paths[path].copy(update=family), force=True)
self.paths[path].xmlfiles.append(filename)
force_not_first = True
else:
extra_attrs = set(family_obj) - self.family_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
self.add_family(subpath,
path,
name,
family_obj,
filename,
)
if family_is_dynamic:
self.dynamics.append(path)
force_not_first = False
if self.paths[path].type == 'dynamic':
family_is_dynamic = True
elif self.paths[path].type == 'leadership':
family_is_leadership = True
for idx, key in enumerate(subfamily_obj):
value = subfamily_obj[key]
if not isinstance(value, dict):
raise Exception(f'pfff {key}')
first_variable = not force_not_first and idx == 0
self.family_or_variable(filename,
key,
path,
value,
first_variable,
family_is_leadership,
family_is_dynamic,
)
def add_family(self,
subpath: str,
path: str,
name: str,
family: dict,
filename: str,
) -> None:
family['path'] = path
if not isinstance(filename, list):
filename = [filename]
family['xmlfiles'] = filename
if family.get('type', 'family') == 'dynamic':
family_obj = self.dynamic
else:
family_obj = self.family
self.paths.add(path, family_obj(name=name, **family))
self.set_name(self.paths[path], 'optiondescription_')
self.parents[subpath].append(path)
self.parents[path] = []
self.families.append(path)
def parse_variable(self,
filename: str,
name: str,
subpath: str,
path: str,
variable: dict,
first_variable: bool,
family_is_leadership: bool,
family_is_dynamic: bool,
) -> None:
extra_attrs = set(variable) - self.variable_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
if path in self.paths:
if 'exists' in variable and not variable['exists']:
return
if not variable.pop('redefine', False):
raise Exception('pfff')
self.paths.add(path, self.paths[path].copy(update=variable), force=True)
self.paths[path].xmlfiles.append(filename)
else:
if 'exists' in variable and variable.pop('exists'):
# this variable must exist
# but it's not the case
# so do nothing
return
if 'redefine' in variable and variable['redefine']:
raise Exception('cannot redefine!')
self.add_variable(subpath,
path,
name,
variable,
filename,
)
if family_is_leadership:
if first_variable:
self.leaders.append(path)
else:
self.followers.append(path)
if family_is_dynamic:
self.dynamics.append(path)
def add_variable(self,
subpath: str,
path: str,
name: str,
variable: dict,
filename: str,
) -> None:
variable['path'] = path
if not isinstance(filename, list):
filename = [filename]
variable['xmlfiles'] = filename
if variable.get('type') == 'symlink':
variable_obj = SymLink(name=name, **variable)
else:
variable_obj = self.variable(name=name, **variable)
self.paths.add(path, variable_obj)
self.variables.append(path)
self.parents[subpath].append(path)
self.set_name(variable_obj, 'option_')
def del_family(self,
path: str,
) -> None:
del self.paths[path]
self.families.remove(path)
del self.parents[path]
parent = path.rsplit('.', 1)[0]
self.parents[parent].remove(path)
class ParserService:
def __init__(self):
self.service = Service
self.ip = IP
self.certificate = Certificate
self.file = File
self.override = Override
self.services = {}
self.ips = {}
self.certificates = {}
self.files = {}
self.overrides = {}
def load(self):
self.service_attrs = frozenset(set(get_type_hints(self.service)) | {'redefine', 'type'} - {'name', 'xmlfiles'})
self.ip_attrs = frozenset(set(get_type_hints(self.ip)) - {'name', 'xmlfiles'})
self.certificate_attrs = frozenset(set(get_type_hints(self.certificate)) | {'redefine'} - {'name', 'xmlfiles'})
self.file_attrs = frozenset(set(get_type_hints(self.file)) | {'redefine'} - {'name', 'xmlfiles'})
self.override_attrs = frozenset(set(get_type_hints(self.override)) - {'name', 'xmlfiles'})
def parse_service_file(self,
filename: str,
) -> None:
with open(filename) as o:
objects = safe_load(o)
self.validate_file_version(objects)
for name, obj in objects.items():
self.parse_service(filename,
name,
obj,
)
def parse_service(self,
filename: str,
name: str,
service: dict,
) -> None:
service_obj = {}
subservice_obj = {}
for key, value in service.items():
if key.startswith('_'):
key = key[1:]
if key in self.service_attrs and not isinstance(value, dict):
service_obj[key] = value
else:
subservice_obj[key] = value
if name in self.services:
if service_obj:
if not service.pop('redefine', False):
raise Exception('pfff')
self.services[name] = self.services[name].copy(update=service)
else:
if '.' not in name:
raise Exception('pffff')
extra_attrs = set(service_obj) - self.service_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
service_obj['type'] = name.rsplit('.')[1]
self.services[name] = self.service(name=name, **service_obj)
self.services[name].xmlfiles.append(filename)
for key, value in subservice_obj.items():
if key == 'override':
getattr(self, f'parse_service_{key}')(key, value, f'services.{normalize_family(name)}', filename)
else:
if not isinstance(value, dict):
raise Exception(f'pfff {key}')
for subname, subvalue in value.items():
getattr(self, f'parse_service_{key}')(subname, subvalue, f'services.{normalize_family(name)}', filename)
def parse_service_ip(self,
name: str,
ip: dict,
path: str,
filename: str,
) -> None:
extra_attrs = set(ip) - self.ip_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
self.ips.setdefault(path, []).append(self.ip(name=name, **ip))
self.ips[path][-1].xmlfiles.append(filename)
def parse_service_certificates(self,
name: str,
certificate: dict,
path: str,
filename: str,
) -> None:
extra_attrs = set(certificate) - self.certificate_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
self.certificates.setdefault(path, []).append(self.certificate(name=name, **certificate))
self.certificates[path][-1].xmlfiles.append(filename)
def parse_service_files(self,
name: str,
file: dict,
path: str,
filename: str,
) -> None:
extra_attrs = set(file) - self.file_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
self.files.setdefault(path, []).append(self.file(name=name, **file))
self.files[path][-1].xmlfiles.append(filename)
def parse_service_override(self,
name: str,
override: dict,
path: str,
filename: str,
) -> None:
if override:
extra_attrs = set(override) - self.override_attrs
if extra_attrs:
raise Exception(f'extra attrs ... {extra_attrs}')
self.overrides.setdefault(path, []).append(self.override(name=name, **override))
else:
self.overrides.setdefault(path, []).append(self.override(name=name))
self.overrides[path][-1].xmlfiles.append(filename)
class Parser(ParserVariable, ParserService):
supported_version = ['1.0']
def __init__(self,
rougailconfig: 'RougailConfig'
) -> None:
# FIXME useful?
self.annotator = False
self.rougailconfig = rougailconfig
super().__init__()
def load(self):
super().load()
self.parse_directories()
self.annotate()
self.reflect()
def parse_directories(self) -> None:
for filename in self.get_sorted_filename(self.rougailconfig['dictionaries_dir']):
namespace = self.rougailconfig['variable_namespace']
self.parse_variable_file(filename,
namespace,
# self.rougailconfig['variable_namespace_description'],
)
for namespace, extra_dirs in self.rougailconfig['extra_dictionaries'].items():
for filename in self.get_sorted_filename(extra_dirs):
self.parse_variable_file(filename,
namespace,
# namespace,
)
for filename in self.get_sorted_filename(self.rougailconfig['services_dir']):
self.parse_service_file(filename)
def get_sorted_filename(self,
directories: Union[str, List[str]],
) -> List[str]:
filenames = {}
if not isinstance(directories, list):
directories = [directories]
for directory in directories:
if not isdir(directory):
continue
for filename in listdir(directory):
if not filename.endswith('.yml'):
continue
full_filename = join(directory, filename)
if filename in filenames:
raise DictConsistencyError(_(f'duplicate dictionary file name {filename}'), 78, [filenames[filename][1], full_filename])
filenames[filename] = full_filename
for filename in sorted(filenames):
yield filenames[filename]
def validate_file_version(self,
obj: dict,
) -> None:
if 'version' not in obj:
raise Exception('version ...')
version = obj.pop('version')
if version not in self.supported_version:
raise Exception(f'pffff version ... {version} not in {self.supported_version}')
def set_name(self,
obj,
option_prefix,
):
self.index += 1
self.reflector_names[obj.path] = f'{option_prefix}{self.index}{self.rougailconfig["suffix"]}'
def annotate(self):
if self.annotator:
raise DictConsistencyError(_('Cannot execute annotate multiple time'), 85, None)
SpaceAnnotator(self)
self.annotator = True
def reflect(self):
functions_file = self.rougailconfig['functions_file']
if not isinstance(functions_file, list):
functions_file = [functions_file]
functions_file = [func for func in functions_file if func not in self.exclude_imports]
self.reflector = TiramisuReflector(self,
functions_file,
)
def get(self):
return self.reflector.get_text()

View file

@ -587,24 +587,24 @@ class RougailObjSpace:
getattr(space, child.tag).append(variableobj) getattr(space, child.tag).append(variableobj)
else: else:
setattr(space, child.tag, variableobj) setattr(space, child.tag, variableobj)
#
#
def get_variables(objectspace): #def get_variables(objectspace):
"""Iter all variables from the objectspace # """Iter all variables from the objectspace
""" # """
if not hasattr(objectspace.space, 'variables'): # if not hasattr(objectspace.space, 'variables'):
return # return
for family in objectspace.space.variables.values(): # for family in objectspace.space.variables.values():
yield from _get_variables(family, objectspace.family) # yield from _get_variables(family, objectspace.family)
#
#
def _get_variables(family, family_type): #def _get_variables(family, family_type):
if hasattr(family, 'variable'): # if hasattr(family, 'variable'):
for variable in family.variable.values(): # for variable in family.variable.values():
if isinstance(variable, family_type): # if isinstance(variable, family_type):
yield from _get_variables(variable, family_type) # yield from _get_variables(variable, family_type)
else: # else:
yield variable # yield variable
if hasattr(family, 'variables'): # if hasattr(family, 'variables'):
for family in family.variables.values(): # for family in family.variables.values():
yield from _get_variables(family, family_type) # yield from _get_variables(family, family_type)

View file

@ -16,26 +16,26 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from rougail.objspace import get_variables #from rougail.objspace import get_variables
from rougail.utils import normalize_family #from rougail.utils import normalize_family
#
#
def provider_supplier(objectspace, #def provider_supplier(objectspace,
path_prefix, # path_prefix,
): # ):
n_path_prefix = normalize_family(path_prefix) # n_path_prefix = normalize_family(path_prefix)
for variable in get_variables(objectspace): # for variable in get_variables(objectspace):
if variable.path_prefix != n_path_prefix: # if variable.path_prefix != n_path_prefix:
continue # continue
if hasattr(variable, 'provider'): # if hasattr(variable, 'provider'):
family_name, variable.name = variable.path.rsplit('.', 1) # family_name, variable.name = variable.path.rsplit('.', 1)
objectspace.paths.set_provider(variable, # objectspace.paths.set_provider(variable,
variable.name, # variable.name,
family_name, # family_name,
) # )
if hasattr(variable, 'supplier'): # if hasattr(variable, 'supplier'):
family_name, variable.name = variable.path.rsplit('.', 1) # family_name, variable.name = variable.path.rsplit('.', 1)
objectspace.paths.set_supplier(variable, # objectspace.paths.set_supplier(variable,
variable.name, # variable.name,
family_name, # family_name,
) # )

View file

@ -1,4 +1,20 @@
from . import none, cheetah, jinja, creole_legacy MODULES = ['none']
from . import none
try:
from . import cheetah
MODULES.append('cheetah')
except ImportError:
pass
try:
from . import creole_legacy
MODULES.append('creole_legacy')
except ImportError:
pass
try:
from . import jinja
MODULES.append('jinja')
except ImportError:
pass
__all__ = ('none', 'cheetah', 'jinja', 'creole_legacy') __all__ = tuple(MODULES)

View file

@ -42,6 +42,7 @@ class BaseElt: # pylint: disable=R0903
"""Base element """Base element
""" """
path = '.' path = '.'
type = 'family'
def sorted_func_name(func_name): def sorted_func_name(func_name):
@ -56,17 +57,15 @@ class TiramisuReflector:
def __init__(self, def __init__(self,
objectspace, objectspace,
funcs_paths, funcs_paths,
internal_functions,
cfg,
): ):
self.cfg = cfg self.rougailconfig = objectspace.rougailconfig
self.jinja_added = False self.jinja_added = False
self.reflector_objects = {}
self.text = {'header': [], self.text = {'header': [],
'option': [], 'option': [],
'optiondescription': [],
} }
if funcs_paths: if funcs_paths:
if self.cfg['export_with_import']: if self.rougailconfig['export_with_import']:
self.text['header'].extend(["from importlib.machinery import SourceFileLoader as _SourceFileLoader", self.text['header'].extend(["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", "from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec",
"class func:", "class func:",
@ -87,9 +86,9 @@ class TiramisuReflector:
if not isfile(funcs_path): if not isfile(funcs_path):
continue continue
self.text['header'].append(f"_load_functions('{funcs_path}')") self.text['header'].append(f"_load_functions('{funcs_path}')")
if self.cfg['export_with_import']: if self.rougailconfig['export_with_import']:
if internal_functions: if self.rougailconfig['internal_functions']:
for func in internal_functions: for func in self.rougailconfig['internal_functions']:
self.text['header'].append(f"setattr(func, '{func}', {func})") self.text['header'].append(f"setattr(func, '{func}', {func})")
self.text['header'].extend(["try:", self.text['header'].extend(["try:",
" from tiramisu4 import *", " from tiramisu4 import *",
@ -98,12 +97,12 @@ class TiramisuReflector:
" from tiramisu import *", " from tiramisu import *",
" from tiramisu.setting import ALLOWED_LEADER_PROPERTIES", " from tiramisu.setting import ALLOWED_LEADER_PROPERTIES",
]) ])
for mode in objectspace.rougailconfig["modes_level"]: for mode in self.rougailconfig["modes_level"]:
self.text['header'].append(f'ALLOWED_LEADER_PROPERTIES.add("{mode}")') self.text['header'].append(f'ALLOWED_LEADER_PROPERTIES.add("{mode}")')
self.objectspace = objectspace self.objectspace = objectspace
self.make_tiramisu_objects() self.make_tiramisu_objects()
if self.cfg['export_with_import'] and (self.cfg['force_convert_dyn_option_description'] or self.objectspace.has_dyn_option is True): #FIXME if self.rougailconfig['export_with_import'] and (self.rougailconfig['force_convert_dyn_option_description'] or self.objectspace.has_dyn_option is True):
self.text['header'].append("from rougail.tiramisu import ConvertDynOptionDescription") # self.text['header'].append("from rougail.tiramisu import ConvertDynOptionDescription")
def add_jinja_to_function(self, def add_jinja_to_function(self,
variable_name: str, variable_name: str,
@ -146,20 +145,30 @@ class TiramisuReflector:
"""make tiramisu objects """make tiramisu objects
""" """
baseelt = BaseElt() baseelt = BaseElt()
baseelt.reflector_name = f'option_0{self.objectspace.rougailconfig["suffix"]}' self.objectspace.reflector_names[baseelt.path] = f'option_0{self.rougailconfig["suffix"]}'
self.set_name(baseelt)
basefamily = Family(baseelt, basefamily = Family(baseelt,
self, self,
) )
if not self.objectspace.paths.has_path_prefix(): #FIXMEif not self.objectspace.paths.has_path_prefix():
for elt in self.reorder_family(self.objectspace.space): if 1:
self.populate_family(basefamily, # for elt in self.reorder_family(self.objectspace.space):
elt, for elt in self.objectspace.paths.get():
) if elt.path in self.objectspace.families:
if not hasattr(basefamily.elt, 'information'): Family(elt,
basefamily.elt.information = self.objectspace.information(None) self,
basefamily.elt.information = self.objectspace.paths.get_providers_path() )
basefamily.elt.information.update(self.objectspace.paths.get_suppliers_path()) else:
Variable(elt,
self,
)
# self.populate_family(basefamily,
# elt,
# )
#FIXME if not hasattr(basefamily.elt, 'information'):
# basefamily.elt.information = self.objectspace.information(None)
# basefamily.elt.information = self.objectspace.paths.get_providers_path()
# basefamily.elt.information.update(self.objectspace.paths.get_suppliers_path())
else: else:
path_prefixes = self.objectspace.paths.get_path_prefixes() path_prefixes = self.objectspace.paths.get_path_prefixes()
for path_prefix in path_prefixes: for path_prefix in path_prefixes:
@ -179,66 +188,66 @@ class TiramisuReflector:
setattr(baseprefix.elt.information, key, value) setattr(baseprefix.elt.information, key, value)
for key, value in self.objectspace.paths.get_suppliers_path(path_prefix).items(): for key, value in self.objectspace.paths.get_suppliers_path(path_prefix).items():
setattr(baseprefix.elt.information, key, value) setattr(baseprefix.elt.information, key, value)
baseelt.name = normalize_family(self.cfg['base_option_name']) baseelt.name = normalize_family(self.rougailconfig['base_option_name'])
baseelt.doc = self.cfg['base_option_name'] baseelt.description = self.rougailconfig['base_option_name']
baseelt.reflector_object.get([], baseelt.doc, 'base') # pylint: disable=E1101 self.reflector_objects[baseelt.path].get([], baseelt.description, 'base') # pylint: disable=E1101
#
def reorder_family(self, space): # def reorder_family(self, space):
"""variable_namespace family has to be loaded before any other family # """family has to be loaded before any other family
because `extra` family could use `variable_namespace` variables. # because `extra` family could use `variable_namespace` variables.
""" # """
if hasattr(space, 'variables'): # if hasattr(space, 'variables'):
variable_namespace = self.objectspace.rougailconfig['variable_namespace'] # variable_namespace = self.rougailconfig['variable_namespace']
if variable_namespace in space.variables: # if variable_namespace in space.variables:
yield space.variables[variable_namespace] # yield space.variables[variable_namespace]
for elt, value in space.variables.items(): # for elt, value in space.variables.items():
if elt != self.objectspace.rougailconfig['variable_namespace']: # if elt != self.rougailconfig['variable_namespace']:
yield value # yield value
if hasattr(space, 'services'): # if hasattr(space, 'services'):
yield space.services # yield space.services
#
def populate_family(self, # def populate_family(self,
parent_family, # parent_family,
elt, # elt,
): # ):
"""Populate family # """Populate family
""" # """
self.set_name(elt) # self.set_name(elt)
family = Family(elt, # family = Family(elt,
self, # self,
) # )
parent_family.add(family) # parent_family.add(family)
for children in vars(elt).values(): # for children in vars(elt).values():
if isinstance(children, self.objectspace.family): # if isinstance(children, self.objectspace.family):
self.populate_family(family, # self.populate_family(family,
children, # children,
) # )
continue # continue
if isinstance(children, dict): # if isinstance(children, dict):
children = list(children.values()) # children = list(children.values())
if isinstance(children, list): # if isinstance(children, list):
for child in children: # for child in children:
if isinstance(child, self.objectspace.property_) or \ # if isinstance(child, self.objectspace.property_) or \
not isinstance(child, RootRougailObject): # not isinstance(child, RootRougailObject):
continue # continue
if isinstance(child, self.objectspace.variable): # if isinstance(child, self.objectspace.variable):
self.set_name(child) # self.set_name(child)
family.add(Variable(child, # family.add(Variable(child,
self, # self,
)) # ))
else: # else:
self.populate_family(family, # self.populate_family(family,
child, # child,
) # )
def set_name(self, def set_name(self,
elt, elt,
): ):
"""Set name """Set name
""" """
if not hasattr(elt, 'reflector_name'): if elt.path not in self.objectspace.reflector_names:
self.objectspace.paths.set_name(elt, 'optiondescription_') self.objectspace.set_name(elt, 'optiondescription_')
return elt.reflector_name return self.objectspace.reflector_names[elt.path]
def get_text(self): def get_text(self):
"""Get text """Get text
@ -247,7 +256,7 @@ class TiramisuReflector:
self.text['header'].extend(["ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)", self.text['header'].extend(["ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)",
"ENV.compile_templates('jinja_caches', zip=None)", "ENV.compile_templates('jinja_caches', zip=None)",
]) ])
return '\n'.join(self.text['header'] + self.text['option'] + self.text['optiondescription']) return '\n'.join(self.text['header'] + self.text['option'])
class Common: class Common:
@ -257,10 +266,11 @@ class Common:
elt, elt,
tiramisu, tiramisu,
): ):
self.objectspace = tiramisu.objectspace
self.elt = elt self.elt = elt
self.option_name = None self.option_name = None
self.tiramisu = tiramisu self.tiramisu = tiramisu
self.elt.reflector_object = self tiramisu.reflector_objects[elt.path] = self
self.object_type = None self.object_type = None
def get(self, calls, parent_name, typ): def get(self, calls, parent_name, typ):
@ -273,7 +283,7 @@ class Common:
self_calls.append(self.elt.path) self_calls.append(self.elt.path)
self.calls = self_calls self.calls = self_calls
if self.option_name is None: if self.option_name is None:
self.option_name = self.elt.reflector_name self.option_name = self.objectspace.reflector_names[self.elt.path]
self.populate_attrib() self.populate_attrib()
self.populate_informations() self.populate_informations()
return self.option_name return self.option_name
@ -282,19 +292,13 @@ class Common:
"""Populate attributes """Populate attributes
""" """
keys = {'name': self.convert_str(self.elt.name)} keys = {'name': self.convert_str(self.elt.name)}
if hasattr(self.elt, 'doc'): if hasattr(self.elt, 'description') and self.elt.description:
keys['doc'] = self.convert_str(self.elt.doc) keys['doc'] = self.convert_str(self.elt.description)
self._populate_attrib(keys) self._populate_attrib(keys)
if hasattr(self.elt, 'properties'): if self.elt.path in self.objectspace.properties:
keys['properties'] = self.properties_to_string(self.elt.properties) keys['properties'] = self.properties_to_string(self.objectspace.properties[self.elt.path])
attrib = ', '.join([f'{key}={value}' for key, value in keys.items()]) attrib = ', '.join([f'{key}={value}' for key, value in keys.items()])
if self.__class__.__name__ == 'Family': self.tiramisu.text['option'].append(f'{self.option_name} = {self.object_type}({attrib})')
#pouet
name = 'option'
#name = 'optiondescription'
else:
name = 'option'
self.tiramisu.text[name].append(f'{self.option_name} = {self.object_type}({attrib})')
def _populate_attrib(self, def _populate_attrib(self,
keys: dict, keys: dict,
@ -315,7 +319,7 @@ class Common:
properties = [self.convert_str(property_) for property_ in values properties = [self.convert_str(property_) for property_ in values
if isinstance(property_, str)] if isinstance(property_, str)]
calc_properties = [self.calc_properties(property_) for property_ in values \ calc_properties = [self.calc_properties(property_) for property_ in values \
if isinstance(property_, self.tiramisu.objectspace.property_)] if isinstance(property_, dict)]
return 'frozenset({' + ', '.join(sorted(properties) + calc_properties) + '})' return 'frozenset({' + ', '.join(sorted(properties) + calc_properties) + '})'
def calc_properties(self, def calc_properties(self,
@ -323,7 +327,7 @@ class Common:
) -> str: ) -> str:
"""Populate properties """Populate properties
""" """
option_name = child.source.reflector_object.get(self.calls, self.elt.path, 'property') option_name = self.tiramisu.reflector_objects[child.source.path].get(self.calls, self.elt.path, 'property')
kwargs = (f"'condition': ParamOption({option_name}, notraisepropertyerror=True), " kwargs = (f"'condition': ParamOption({option_name}, notraisepropertyerror=True), "
f"'expected': {self.populate_param(child.expected)}") f"'expected': {self.populate_param(child.expected)}")
if child.inverse: if child.inverse:
@ -334,15 +338,10 @@ class Common:
def populate_informations(self): def populate_informations(self):
"""Populate Tiramisu's informations """Populate Tiramisu's informations
""" """
if not hasattr(self.elt, 'information'): informations = self.objectspace.informations.get(self.elt.path)
if not informations:
return return
if isinstance(self.elt.information, dict):
informations = self.elt.information
else:
informations = vars(self.elt.information)
for key, value in informations.items(): for key, value in informations.items():
if key == 'xmlfiles':
continue
if isinstance(value, str): if isinstance(value, str):
value = self.convert_str(value) value = self.convert_str(value)
self.tiramisu.text['option'].append(f"{self.option_name}.impl_set_information('{key}', {value})") self.tiramisu.text['option'].append(f"{self.option_name}.impl_set_information('{key}', {value})")
@ -352,10 +351,10 @@ class Common:
): ):
"""Populate variable parameters """Populate variable parameters
""" """
if param.type in ['number', 'boolean', 'nil', 'port', 'choice', 'space']: if isinstance(param, self.objectspace.variable):
return f'ParamValue({param.text})'
if param.type in ['variable_name', 'variable']:
return self.build_option_param(param) return self.build_option_param(param)
if not isinstance(param, self.objectspace.param):
return f'ParamValue({param})'
if param.type == 'information': if param.type == 'information':
if hasattr(self.elt, 'multi') and self.elt.multi: if hasattr(self.elt, 'multi') and self.elt.multi:
default = [] default = []
@ -364,15 +363,12 @@ class Common:
if hasattr(param, 'variable'): if hasattr(param, 'variable'):
if param.variable.path == self.elt.path: if param.variable.path == self.elt.path:
return f'ParamSelfInformation("{param.text}", {default})' return f'ParamSelfInformation("{param.text}", {default})'
return f'ParamInformation("{param.text}", {default}, option={param.variable.reflector_object.get(self.calls, self.elt.path, "param")})' return f'ParamInformation("{param.text}", {default}, option={self.tiramisu.reflector_objects[param.variable.path].get(self.calls, self.elt.path, "param")})'
return f'ParamInformation("{param.text}", {default})' return f'ParamInformation("{param.text}", {default})'
if param.type == 'suffix': if param.type == 'suffix':
return 'ParamSuffix()' return 'ParamSuffix()'
if param.type == 'index': if param.type == 'index':
return 'ParamIndex()' return 'ParamIndex()'
if param.type == 'jinja':
self.tiramisu.add_jinja_to_function(self.elt.path, param.text)
return f'ParamValue("{self.elt.path}")'
value = self.convert_str(param.text) value = self.convert_str(param.text)
return f'ParamValue({value})' return f'ParamValue({value})'
@ -381,21 +377,18 @@ class Common:
) -> str: ) -> str:
"""build variable parameters """build variable parameters
""" """
if param.type == 'variable': option_name = self.tiramisu.reflector_objects[param.path].get(self.calls, self.elt.path, 'param')
option_name = param.text.reflector_object.get(self.calls, self.elt.path, 'param')
else:
option_name = param.text
params = [f'{option_name}'] params = [f'{option_name}']
if hasattr(param, 'suffix'): if hasattr(param, 'suffix'):
param_type = 'ParamDynOption' param_type = 'ParamDynOption'
family = param.family.reflector_object.get(self.calls, self.elt.path, 'suffix') family = self.tiramisu.reflector_objects[param.family.path].get(self.calls, self.elt.path, 'suffix')
params.extend([f"'{param.suffix}'", f'{family}']) params.extend([f"'{param.suffix}'", f'{family}'])
if param.optional: if param.optional:
params.append('optional=True') params.append('optional=True')
else: else:
param_type = 'ParamOption' param_type = 'ParamOption'
if not param.propertyerror: # if not param.propertyerror:
params.append('notraisepropertyerror=True') # params.append('notraisepropertyerror=True')
return "{}({})".format(param_type, ', '.join(params)) return "{}({})".format(param_type, ', '.join(params))
@ -412,30 +405,37 @@ class Variable(Common):
def _populate_attrib(self, def _populate_attrib(self,
keys: dict, keys: dict,
): ):
if hasattr(self.elt, 'opt'): if self.elt.type == 'symlink':
keys['opt'] = self.elt.opt.reflector_object.get(self.calls, self.elt.path, 'opt') keys['opt'] = self.tiramisu.reflector_objects[self.elt.opt.path].get(self.calls, self.elt.path, 'opt')
if hasattr(self.elt, 'choice'): if hasattr(self.elt, 'choices') and self.elt.choices:
values = self.elt.choice values = self.elt.choices
if values[0].type == 'variable': if isinstance(values[0], dict):
value = values[0].name.reflector_object.get(self.calls, self.elt.path, 'choice') if values[0]['type'] == 'variable':
keys['values'] = f"Calculation(func.calc_value, Params((ParamOption({value}))))" value = self.tiramisu.reflector_objects[values[0]['variable'].path].get(self.calls, self.elt.path, 'choice')
elif values[0].type == 'function': keys['values'] = f"Calculation(func.calc_value, Params((ParamOption({value}))))"
keys['values'] = self.calculation_value(values[0], []) elif values[0]['type'] == 'jinja':
keys['values'] = self.calculation_value(values[0], [])
else: else:
keys['values'] = str(tuple([val.name for val in values])) keys['values'] = str(tuple(values))
if hasattr(self.elt, 'multi') and self.elt.multi: if self.elt.path in self.objectspace.multis:
keys['multi'] = self.elt.multi keys['multi'] = self.objectspace.multis[self.elt.path]
for key in ['default', 'default_multi']: if hasattr(self.elt, 'default') and self.elt.default is not None:
if hasattr(self.elt, key) and getattr(self.elt, key) is not None: value = self.elt.default
value = getattr(self.elt, key) if isinstance(value, str):
if isinstance(value, str): value = self.convert_str(value)
value = self.convert_str(value) elif isinstance(value, dict):
elif isinstance(value, self.tiramisu.objectspace.value): value = self.calculation_value(value, [], False) # calc_multi=key == 'calc_multi')
value = self.calculation_value(value, [], calc_multi=value.calc_multi) keys['default'] = value
keys[key] = value if self.elt.path in self.objectspace.default_multi:
if hasattr(self.elt, 'validators'): value = self.objectspace.default_multi[self.elt.path]
keys['validators'] = '[' + ', '.join([self.calculation_value(val, if isinstance(value, str):
['ParamSelfOption(whole=False)']) for val in self.elt.validators]) + ']' value = self.convert_str(value)
elif isinstance(value, dict):
value = self.calculation_value(value, [], False) # calc_multi=key == 'calc_multi')
keys['default_multi'] = value
#FIXME if self.elt.validators:
# keys['validators'] = '[' + ', '.join([self.calculation_value(val,
# ['ParamSelfOption(whole=False)']) for val in self.elt.validators]) + ']'
for key in ['min_number', 'max_number']: for key in ['min_number', 'max_number']:
if hasattr(self.elt, key): if hasattr(self.elt, key):
keys[key] = getattr(self.elt, key) keys[key] = getattr(self.elt, key)
@ -451,22 +451,21 @@ class Variable(Common):
) -> str: ) -> str:
"""Generate calculated value """Generate calculated value
""" """
kwargs = [] if child['type'] == 'jinja':
self.tiramisu.add_jinja_to_function(self.elt.path, child['jinja'])
function = 'jinja_to_function'
else:
raise Exception("connard")
# has parameters # has parameters
function = child.name
new_args = [] new_args = []
if hasattr(child, 'param'): kwargs = []
for param in child.param: if 'params' in child:
value = self.populate_param(param) for key, value in child['params'].items():
if not hasattr(param, 'name'): value = self.populate_param(value)
if not key:
new_args.append(str(value)) new_args.append(str(value))
else: else:
kwargs.append(f"'{param.name}': " + value) kwargs.append(f"'{key}': " + value)
if function == 'valid_network_netmask':
new_args.extend(args)
else:
args.extend(new_args)
new_args = args
ret = f'Calculation(func.{function}, Params((' + ', '.join(new_args) + ')' ret = f'Calculation(func.{function}, Params((' + ', '.join(new_args) + ')'
if kwargs: if kwargs:
ret += ', kwargs={' + ', '.join(kwargs) + '}' ret += ', kwargs={' + ', '.join(kwargs) + '}'
@ -487,10 +486,10 @@ class Family(Common):
tiramisu, tiramisu,
): ):
super().__init__(elt, tiramisu) super().__init__(elt, tiramisu)
if hasattr(self.elt, 'suffixes'): if self.elt.type == 'dynamic':
self.tiramisu.objectspace.has_dyn_option = True self.tiramisu.objectspace.has_dyn_option = True
self.object_type = 'ConvertDynOptionDescription' self.object_type = 'ConvertDynOptionDescription'
elif hasattr(self.elt, 'leadership') and self.elt.leadership: elif self.elt.type == 'leadership':
self.object_type = 'Leadership' self.object_type = 'Leadership'
else: else:
self.object_type = 'OptionDescription' self.object_type = 'OptionDescription'
@ -504,7 +503,10 @@ class Family(Common):
def _populate_attrib(self, def _populate_attrib(self,
keys: list, keys: list,
) -> None: ) -> None:
if hasattr(self.elt, 'suffixes'): if self.elt.type == 'dynamic':
dyn = self.elt.suffixes.reflector_object.get(self.calls, self.elt.path, 'suffixes') dyn = self.tiramisu.reflector_objects[self.elt.variable.path].get(self.calls, self.elt.path, 'suffixes')
keys['suffixes'] = f"Calculation(func.calc_value, Params((ParamOption({dyn}, notraisepropertyerror=True))))" keys['suffixes'] = f"Calculation(func.calc_value, Params((ParamOption({dyn}, notraisepropertyerror=True))))"
keys['children'] = '[' + ', '.join([child.get(self.calls, self.elt.path, 'child') for child in self.children]) + ']' children = []
for path in self.objectspace.parents[self.elt.path]:
children.append(self.objectspace.paths[path])
keys['children'] = '[' + ', '.join([self.tiramisu.reflector_objects[child.path].get(self.calls, self.elt.path, 'child') for child in children]) + ']'

File diff suppressed because it is too large Load diff

View file

@ -1,10 +0,0 @@
{
"rougail.myvar": {
"owner": "forced",
"value": "no"
},
"rougail.server_deployed": {
"owner": "default",
"value": false
}
}

View file

@ -1,4 +0,0 @@
{
"rougail.myvar": "no",
"rougail.server_deployed": false
}

View file

@ -1,10 +0,0 @@
{
"rougail.myvar": {
"owner": "default",
"value": "no"
},
"rougail.server_deployed": {
"owner": "default",
"value": false
}
}

View file

@ -1,29 +0,0 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=False, properties=frozenset({"mandatory", "normal"}))
option_1 = StrOption(name="myvar", doc="myvar", default="no", properties=frozenset({"basic", "force_store_value", "mandatory", Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_2, notraisepropertyerror=True), 'expected': ParamValue(True)}), func.calc_value_property_help)}))
optiondescription_3 = OptionDescription(name="rougail", doc="Rougail", children=[option_1, option_2], properties=frozenset({"basic"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_3])

View file

@ -1,34 +0,0 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=False, properties=frozenset({"mandatory", "normal"}))
option_1 = StrOption(name="myvar", doc="myvar", default="no", properties=frozenset({"basic", "force_store_value", "mandatory", Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_2, notraisepropertyerror=True), 'expected': ParamValue(True)}), func.calc_value_property_help)}))
optiondescription_6 = OptionDescription(name="rougail", doc="Rougail", children=[option_1, option_2], properties=frozenset({"basic"}))
optiondescription_5 = OptionDescription(name="1", doc="1", children=[optiondescription_6])
option_4 = BoolOption(name="server_deployed", doc="server_deployed", default=False, properties=frozenset({"mandatory", "normal"}))
option_3 = StrOption(name="myvar", doc="myvar", default="no", properties=frozenset({"basic", "force_store_value", "mandatory", Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_4, notraisepropertyerror=True), 'expected': ParamValue(True)}), func.calc_value_property_help)}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[option_3, option_4], properties=frozenset({"basic"}))
optiondescription_7 = OptionDescription(name="2", doc="2", children=[optiondescription_8])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_5, optiondescription_7])

View file

@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<variable name="myvar" auto_freeze="True">
<value>no</value>
</variable>
<variable name="server_deployed" type="boolean">
<value>False</value>
</variable>
</variables>
</rougail>

View file

@ -1,11 +0,0 @@
version: '0.10'
variables:
- variable:
- name: myvar
auto_freeze: true
value:
- text: 'no'
- name: server_deployed
type: boolean
value:
- text: false

View file

@ -1,7 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<services>
<service name="tata">
</service>
</services>
</rougail>

View file

@ -1,9 +1,9 @@
{ {
"services.tata.activate": { "services.tata_service.activate": {
"owner": "default", "owner": "default",
"value": true "value": true
}, },
"services.tata.manage": { "services.tata_service.manage": {
"owner": "default", "owner": "default",
"value": true "value": true
} }

View file

@ -1,4 +1,4 @@
{ {
"services.tata.activate": true, "services.tata_service.activate": true,
"services.tata.manage": true "services.tata_service.manage": true
} }

View file

@ -1,9 +1,9 @@
{ {
"services.tata.activate": { "services.tata_service.activate": {
"owner": "default", "owner": "default",
"value": true "value": true
}, },
"services.tata.manage": { "services.tata_service.manage": {
"owner": "default", "owner": "default",
"value": true "value": true
} }

View file

@ -0,0 +1,2 @@
tata.service: {}
version: '1.0'

View file

@ -1,18 +1,31 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_3 = BoolOption(name="activate", doc="activate", default=True) option_3 = BoolOption(name="activate", doc="activate", default=True)
option_4 = BoolOption(name="manage", doc="manage", default=True) option_4 = BoolOption(name="manage", doc="manage", default=True)
option_2 = OptionDescription(name="tata", doc="tata", children=[option_3, option_4]) optiondescription_2 = OptionDescription(name="tata_service", doc="tata_service", children=[option_3, option_4])
option_1 = OptionDescription(name="services", doc="services", children=[option_2], properties=frozenset({"hidden"})) optiondescription_2.impl_set_information('type', "service")
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) optiondescription_1 = OptionDescription(name="services", doc="services", children=[optiondescription_2], properties=frozenset({"hidden", "normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_1 = BoolOption(name="activate", doc="activate", default=True)
option_2 = BoolOption(name="manage", doc="manage", default=True)
optiondescription_7 = OptionDescription(name="tata_service", doc="tata.service", children=[option_1, option_2])
optiondescription_7.impl_set_information('type', "service")
optiondescription_6 = OptionDescription(name="services", doc="services", children=[optiondescription_7], properties=frozenset({"hidden"}))
optiondescription_5 = OptionDescription(name="1", doc="1", children=[optiondescription_6])
option_3 = BoolOption(name="activate", doc="activate", default=True)
option_4 = BoolOption(name="manage", doc="manage", default=True)
optiondescription_10 = OptionDescription(name="tata_service", doc="tata.service", children=[option_3, option_4])
optiondescription_10.impl_set_information('type', "service")
optiondescription_9 = OptionDescription(name="services", doc="services", children=[optiondescription_10], properties=frozenset({"hidden"}))
optiondescription_8 = OptionDescription(name="2", doc="2", children=[optiondescription_9])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_5, optiondescription_8])

View file

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<services>
<service name="tata">
</service>
</services>
</rougail>

View file

@ -0,0 +1,4 @@
version: '0.10'
services:
- service:
- name: tata

View file

@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<variable name="myvar" auto_freeze="True">
<value>no</value>
</variable>
<variable name="server_deployed" type="boolean">
<value>False</value>
</variable>
</variables>
</rougail>

View file

@ -1,10 +0,0 @@
{
"rougail.myvar": {
"owner": "forced",
"value": "no"
},
"rougail.server_deployed": {
"owner": "default",
"value": false
}
}

View file

@ -1,4 +0,0 @@
{
"rougail.myvar": "no",
"rougail.server_deployed": false
}

View file

@ -1,10 +0,0 @@
{
"rougail.myvar": {
"owner": "default",
"value": "no"
},
"rougail.server_deployed": {
"owner": "default",
"value": false
}
}

View file

@ -1,17 +0,0 @@
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 tiramisu4 import *
except:
from tiramisu import *
option_3 = BoolOption(name="server_deployed", doc="server_deployed", default=False, properties=frozenset({"mandatory", "normal"}))
option_2 = StrOption(name="myvar", doc="myvar", default="no", properties=frozenset({"basic", "force_store_value", "mandatory", Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_3, todict=True, notraisepropertyerror=True), 'expected': ParamValue(True)}))}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<variable name="my_var" auto_freeze="True" mode="expert">
<value>no</value>
</variable>
<variable name="server_deployed" type="boolean">
<value>False</value>
</variable>
</variables>
</rougail>

View file

@ -1,10 +0,0 @@
{
"rougail.my_var": {
"owner": "forced",
"value": "no"
},
"rougail.server_deployed": {
"owner": "default",
"value": false
}
}

View file

@ -1,4 +0,0 @@
{
"rougail.my_var": "no",
"rougail.server_deployed": false
}

View file

@ -1,10 +0,0 @@
{
"rougail.my_var": {
"owner": "default",
"value": "no"
},
"rougail.server_deployed": {
"owner": "default",
"value": false
}
}

View file

@ -1,17 +0,0 @@
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 tiramisu4 import *
except:
from tiramisu import *
option_3 = BoolOption(name="server_deployed", doc="server_deployed", default=False, properties=frozenset({"mandatory", "normal"}))
option_2 = StrOption(name="my_var", doc="my_var", default="no", properties=frozenset({"expert", "force_store_value", "mandatory", Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_3, todict=True, notraisepropertyerror=True), 'expected': ParamValue(True)}))}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<variable name="server_deployed" type="boolean"/>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" auto_save="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,10 @@
server_deployed:
type: boolean
general:
description: général
mode_conteneur_actif:
type: string
description: No change
auto_save: true
default: non
version: '1.0'

View file

@ -1,18 +1,30 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"})) option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"}))
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"basic", "force_store_value", "mandatory"})) option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"basic", "force_store_value", "mandatory"}))
option_3 = OptionDescription(name="general", doc="général", children=[option_4], properties=frozenset({"basic"})) optiondescription_3 = OptionDescription(name="general", doc="général", children=[option_4], properties=frozenset({"basic"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3]) optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, optiondescription_3], properties=frozenset({"basic"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,36 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_1 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"}))
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"basic", "force_store_value", "mandatory"}))
optiondescription_2 = OptionDescription(name="general", doc="général", children=[option_3], properties=frozenset({"basic"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[option_1, optiondescription_2], properties=frozenset({"basic"}))
optiondescription_7 = OptionDescription(name="1", doc="1", children=[optiondescription_8])
option_4 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"}))
option_6 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"basic", "force_store_value", "mandatory"}))
optiondescription_5 = OptionDescription(name="general", doc="général", children=[option_6], properties=frozenset({"basic"}))
optiondescription_10 = OptionDescription(name="rougail", doc="Rougail", children=[option_4, optiondescription_5], properties=frozenset({"basic"}))
optiondescription_9 = OptionDescription(name="2", doc="2", children=[optiondescription_10])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_7, optiondescription_9])

View file

@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<variable name="server_deployed" type="boolean"/>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" auto_save="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,16 @@
version: '0.10'
variables:
- variable:
- name: server_deployed
type: boolean
- family:
- name: general
description: "g\xE9n\xE9ral"
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
auto_save: true
value:
- text: non

View file

@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<variable name="server_deployed" type="boolean"/>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" auto_save="True" mode="expert">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,11 @@
server_deployed:
type: boolean
general:
description: général
mode_conteneur_actif:
type: string
description: No change
auto_save: true
mode: expert
default: non
version: '1.0'

View file

@ -1,18 +1,30 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"})) option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"}))
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "force_store_value", "mandatory"})) option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "force_store_value", "mandatory"}))
option_3 = OptionDescription(name="general", doc="général", children=[option_4], properties=frozenset({"expert"})) optiondescription_3 = OptionDescription(name="general", doc="général", children=[option_4], properties=frozenset({"expert"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3]) optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, optiondescription_3], properties=frozenset({"normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,36 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_1 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"}))
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "force_store_value", "mandatory"}))
optiondescription_2 = OptionDescription(name="general", doc="général", children=[option_3], properties=frozenset({"expert"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[option_1, optiondescription_2], properties=frozenset({"normal"}))
optiondescription_7 = OptionDescription(name="1", doc="1", children=[optiondescription_8])
option_4 = BoolOption(name="server_deployed", doc="server_deployed", default=True, properties=frozenset({"mandatory", "normal"}))
option_6 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"expert", "force_store_value", "mandatory"}))
optiondescription_5 = OptionDescription(name="general", doc="général", children=[option_6], properties=frozenset({"expert"}))
optiondescription_10 = OptionDescription(name="rougail", doc="Rougail", children=[option_4, optiondescription_5], properties=frozenset({"normal"}))
optiondescription_9 = OptionDescription(name="2", doc="2", children=[optiondescription_10])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_7, optiondescription_9])

View file

@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<variable name="server_deployed" type="boolean"/>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" auto_save="True" mode="expert">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,17 @@
version: '0.10'
variables:
- variable:
- name: server_deployed
type: boolean
- family:
- name: general
description: "g\xE9n\xE9ral"
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
auto_save: true
mode: expert
value:
- text: non

View file

@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<family name="general" description="général">
<!-- this is a comment -->
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,8 @@
general:
description: général
mode_conteneur_actif:
type: string
description: No change
hidden: true
default: non
version: '1.0'

View file

@ -1,17 +1,29 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", 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"})) optiondescription_2 = OptionDescription(name="general", doc="général", children=[option_3], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,34 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
optiondescription_1 = OptionDescription(name="general", doc="général", children=[option_2], properties=frozenset({"normal"}))
optiondescription_6 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_1], properties=frozenset({"normal"}))
optiondescription_5 = OptionDescription(name="1", doc="1", children=[optiondescription_6])
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
optiondescription_3 = OptionDescription(name="general", doc="général", children=[option_4], properties=frozenset({"normal"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_3], properties=frozenset({"normal"}))
optiondescription_7 = OptionDescription(name="2", doc="2", children=[optiondescription_8])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_5, optiondescription_7])

View file

@ -0,0 +1,11 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general" description="général">
<!-- this is a comment -->
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,13 @@
version: '0.10'
variables:
- family:
- name: general
description: "g\xE9n\xE9ral"
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
hidden: true
value:
- text: non

View file

@ -1,13 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
<variable name="without_type">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,10 @@
general:
description: général
mode_conteneur_actif:
type: string
description: No change
hidden: true
default: non
without_type:
default: non
version: '1.0'

View file

@ -1,18 +1,30 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
option_4 = StrOption(name="without_type", doc="without_type", default="non", properties=frozenset({"mandatory", "normal"})) option_4 = StrOption(name="without_type", doc="without_type", default="non", properties=frozenset({"mandatory", "normal"}))
option_2 = OptionDescription(name="general", doc="général", children=[option_3, option_4], properties=frozenset({"normal"})) optiondescription_2 = OptionDescription(name="general", doc="général", children=[option_3, option_4], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,36 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
option_3 = StrOption(name="without_type", doc="without_type", default="non", properties=frozenset({"mandatory", "normal"}))
optiondescription_1 = OptionDescription(name="general", doc="général", children=[option_2, option_3], properties=frozenset({"normal"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_1], properties=frozenset({"normal"}))
optiondescription_7 = OptionDescription(name="1", doc="1", children=[optiondescription_8])
option_5 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
option_6 = StrOption(name="without_type", doc="without_type", default="non", properties=frozenset({"mandatory", "normal"}))
optiondescription_4 = OptionDescription(name="general", doc="général", children=[option_5, option_6], properties=frozenset({"normal"}))
optiondescription_10 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_4], properties=frozenset({"normal"}))
optiondescription_9 = OptionDescription(name="2", doc="2", children=[optiondescription_10])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_7, optiondescription_9])

View file

@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
<variable name="without_type">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,16 @@
version: '0.10'
variables:
- family:
- name: general
description: "g\xE9n\xE9ral"
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
hidden: true
value:
- text: non
- name: without_type
value:
- text: non

View file

@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,8 @@
general:
description: général
mode_conteneur_actif:
type: string
description: No change
hidden: true
default: non
version: '1.0'

View file

@ -1,17 +1,29 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", 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"})) optiondescription_2 = OptionDescription(name="general", doc="général", children=[option_3], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,34 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_2 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
optiondescription_1 = OptionDescription(name="general", doc="général", children=[option_2], properties=frozenset({"normal"}))
optiondescription_6 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_1], properties=frozenset({"normal"}))
optiondescription_5 = OptionDescription(name="1", doc="1", children=[optiondescription_6])
option_4 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
optiondescription_3 = OptionDescription(name="general", doc="général", children=[option_4], properties=frozenset({"normal"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_3], properties=frozenset({"normal"}))
optiondescription_7 = OptionDescription(name="2", doc="2", children=[optiondescription_8])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_5, optiondescription_7])

View file

@ -0,0 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -0,0 +1,13 @@
version: '0.10'
variables:
- family:
- name: general
description: "g\xE9n\xE9ral"
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
hidden: true
value:
- text: non

View file

@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<family name="general" description="général">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<family name="general" description="général">
<variable name="mode_conteneur_actif1" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
</variables>
</rougail>

View file

@ -1,18 +0,0 @@
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 tiramisu4 import *
except:
from tiramisu import *
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "mandatory", "normal"}))
option_2 = OptionDescription(name="general", doc="général", children=[option_3, option_4], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -1,17 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<variable name="server_deployed" type="boolean">
<value>no</value>
</variable>
<variable name="my_variable" auto_freeze="True" hidden="True">
<value>no</value>
</variable>
</variables>
<constraints>
<fill name="calc_val">
<param>yes</param>
<target>my_variable</target>
</fill>
</constraints>
</rougail>

View file

@ -1,10 +0,0 @@
{
"rougail.server_deployed": {
"owner": "default",
"value": false
},
"rougail.my_variable": {
"owner": "forced",
"value": "yes"
}
}

View file

@ -1,4 +0,0 @@
{
"rougail.server_deployed": false,
"rougail.my_variable": "yes"
}

View file

@ -1,10 +0,0 @@
{
"rougail.server_deployed": {
"owner": "default",
"value": false
},
"rougail.my_variable": {
"owner": "default",
"value": "yes"
}
}

View file

@ -1,17 +0,0 @@
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 tiramisu4 import *
except:
from tiramisu import *
option_2 = BoolOption(name="server_deployed", doc="server_deployed", default=False, properties=frozenset({"mandatory", "normal"}))
option_3 = StrOption(name="my_variable", doc="my_variable", default=Calculation(func.calc_val, Params((ParamValue("yes")))), properties=frozenset({"basic", "force_store_value", "hidden", Calculation(func.calc_value, Params(ParamValue('frozen'), kwargs={'condition': ParamOption(option_2, todict=True, notraisepropertyerror=True), 'expected': ParamValue(True)}))}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2, option_3])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1])

View file

@ -1,19 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.9">
<variables>
<family name="general">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
<variable name="mode_conteneur_actif1" type="string" description="No change">
<value>non</value>
</variable>
</family>
</variables>
<constraints>
<fill name="calc_val">
<param type="variable">mode_conteneur_actif1</param>
<target>mode_conteneur_actif</target>
</fill>
</constraints>
</rougail>

View file

@ -0,0 +1,13 @@
general:
mode_conteneur_actif:
type: string
description: No change
hidden: true
default:
jinja: '{{ rougail.general.mode_conteneur_actif1 | calc_val }}'
type: jinja
mode_conteneur_actif1:
type: string
description: No change
default: non
version: '1.0'

View file

@ -1,18 +1,60 @@
from importlib.machinery import SourceFileLoader from importlib.machinery import SourceFileLoader as _SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec from importlib.util import spec_from_loader as _spec_from_loader, module_from_spec as _module_from_spec
loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') class func:
spec = spec_from_loader(loader.name, loader) pass
func = module_from_spec(spec)
loader.exec_module(func) def _load_functions(path):
for key, value in dict(locals()).items(): global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
if key != ['SourceFileLoader', 'func']: loader = _SourceFileLoader('func', path)
setattr(func, key, value) 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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try: try:
from tiramisu4 import * from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except: except:
from tiramisu import * from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
from jinja2 import StrictUndefined, DictLoader
from jinja2.sandbox import SandboxedEnvironment
from rougail.annotator.variable import CONVERT_OPTION
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
kw = {}
for key, value in kwargs.items():
if '.' in key:
c_kw = kw
path, var = key.rsplit('.', 1)
for subkey in path.split('.'):
c_kw = c_kw.setdefault(subkey, {})
c_kw[var] = value
else:
kw[key] = value
values = ENV.get_template(__internal_jinja).render(kw)
convert = CONVERT_OPTION[__internal_type].get('func', str)
if __internal_multi:
return [convert(val) for val in values.split(',')]
return convert(values)
def valid_with_jinja(value, **kwargs):
kwargs[kwargs.pop('__internal_key')] = value
value = jinja_to_function(__internal_type='string', __internal_multi=False, **kwargs)
if value:
raise ValueError(value)
func.jinja_to_function = jinja_to_function
func.valid_with_jinja = valid_with_jinja
dict_env = {}
dict_env['rougail.general.mode_conteneur_actif'] = "{{ rougail.general.mode_conteneur_actif1 | calc_val }}"
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
ENV.compile_templates('jinja_caches', zip=None)
option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"})) option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.calc_val, Params((ParamOption(option_4)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"})) option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.jinja_to_function, Params((), kwargs={'__internal_jinja': ParamValue(rougail.general.mode_conteneur_actif), '__internal_type': ParamValue(string), '__internal_multi': ParamValue(False), 'rougail.general.mode_conteneur_actif1': ParamOption(option_4)})), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"}))
option_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"normal"})) optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"normal"}))
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,36 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
option_3 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
option_2 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.calc_val, Params((ParamOption(option_3)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"}))
optiondescription_1 = OptionDescription(name="general", doc="general", children=[option_2, option_3], properties=frozenset({"normal"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_1], properties=frozenset({"normal"}))
optiondescription_7 = OptionDescription(name="1", doc="1", children=[optiondescription_8])
option_6 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
option_5 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.calc_val, Params((ParamOption(option_6)))), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"}))
optiondescription_4 = OptionDescription(name="general", doc="general", children=[option_5, option_6], properties=frozenset({"normal"}))
optiondescription_10 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_4], properties=frozenset({"normal"}))
optiondescription_9 = OptionDescription(name="2", doc="2", children=[optiondescription_10])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_7, optiondescription_9])

View file

@ -0,0 +1,19 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
<variable name="mode_conteneur_actif1" type="string" description="No change">
<value>non</value>
</variable>
</family>
</variables>
<constraints>
<fill name="calc_val">
<param type="variable">mode_conteneur_actif1</param>
<target>mode_conteneur_actif</target>
</fill>
</constraints>
</rougail>

View file

@ -0,0 +1,25 @@
version: '0.10'
variables:
- family:
- name: general
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
hidden: true
value:
- text: non
- name: mode_conteneur_actif1
type: string
description: No change
value:
- text: non
constraints:
- fill:
- name: calc_val
param:
- type: variable
text: mode_conteneur_actif1
target:
- text: mode_conteneur_actif

View file

@ -0,0 +1,13 @@
general:
mode_conteneur_actif:
type: string
description: No change
hidden: true
default:
jinja: '{{ rougail.general.mode_conteneur_actif1 }}'
type: jinja
mode_conteneur_actif1:
type: string
description: No change
default: non
version: '1.0'

View file

@ -0,0 +1,60 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries_old/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
from jinja2 import StrictUndefined, DictLoader
from jinja2.sandbox import SandboxedEnvironment
from rougail.annotator.variable import CONVERT_OPTION
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
kw = {}
for key, value in kwargs.items():
if '.' in key:
c_kw = kw
path, var = key.rsplit('.', 1)
for subkey in path.split('.'):
c_kw = c_kw.setdefault(subkey, {})
c_kw[var] = value
else:
kw[key] = value
values = ENV.get_template(__internal_jinja).render(kw)
convert = CONVERT_OPTION[__internal_type].get('func', str)
if __internal_multi:
return [convert(val) for val in values.split(',')]
return convert(values)
def valid_with_jinja(value, **kwargs):
kwargs[kwargs.pop('__internal_key')] = value
value = jinja_to_function(__internal_type='string', __internal_multi=False, **kwargs)
if value:
raise ValueError(value)
func.jinja_to_function = jinja_to_function
func.valid_with_jinja = valid_with_jinja
dict_env = {}
dict_env['rougail.general.mode_conteneur_actif'] = "{{ rougail.general.mode_conteneur_actif1 }}"
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
ENV.compile_templates('jinja_caches', zip=None)
option_4 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
option_3 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.jinja_to_function, Params((), kwargs={'__internal_jinja': ParamValue(rougail.general.mode_conteneur_actif), '__internal_type': ParamValue(string), '__internal_multi': ParamValue(False), 'rougail.general.mode_conteneur_actif1': ParamOption(option_4)})), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"}))
optiondescription_2 = OptionDescription(name="general", doc="general", children=[option_3, option_4], properties=frozenset({"normal"}))
optiondescription_1 = OptionDescription(name="rougail", doc="rougail", children=[optiondescription_2], properties=frozenset({"normal"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,67 @@
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
def _load_functions(path):
global _SourceFileLoader, _spec_from_loader, _module_from_spec, func
loader = _SourceFileLoader('func', path)
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))
_load_functions('tests/dictionaries/../eosfunc/test.py')
try:
from tiramisu4 import *
from tiramisu4.setting import ALLOWED_LEADER_PROPERTIES
except:
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("normal")
ALLOWED_LEADER_PROPERTIES.add("expert")
from jinja2 import StrictUndefined, DictLoader
from jinja2.sandbox import SandboxedEnvironment
from rougail.annotator.variable import CONVERT_OPTION
def jinja_to_function(__internal_jinja, __internal_type, __internal_multi, **kwargs):
kw = {}
for key, value in kwargs.items():
if '.' in key:
c_kw = kw
path, var = key.rsplit('.', 1)
for subkey in path.split('.'):
c_kw = c_kw.setdefault(subkey, {})
c_kw[var] = value
else:
kw[key] = value
values = ENV.get_template(__internal_jinja).render(kw)
convert = CONVERT_OPTION[__internal_type].get('func', str)
if __internal_multi:
return [convert(val) for val in values.split(',')]
return convert(values)
def valid_with_jinja(value, **kwargs):
kwargs[kwargs.pop('__internal_key')] = value
value = jinja_to_function(__internal_type='string', __internal_multi=False, **kwargs)
if value:
raise ValueError(value)
func.jinja_to_function = jinja_to_function
func.valid_with_jinja = valid_with_jinja
dict_env = {}
dict_env['1.rougail.general.mode_conteneur_actif'] = "{{ mode_conteneur_actif1 }}"
dict_env['2.rougail.general.mode_conteneur_actif'] = "{{ mode_conteneur_actif1 }}"
ENV = SandboxedEnvironment(loader=DictLoader(dict_env), undefined=StrictUndefined)
ENV.compile_templates('jinja_caches', zip=None)
option_3 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
option_2 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.jinja_to_function, Params((), kwargs={'__internal_jinja': ParamValue("1.rougail.general.mode_conteneur_actif"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'mode_conteneur_actif1': ParamOption(option_3)})), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"}))
optiondescription_1 = OptionDescription(name="general", doc="general", children=[option_2, option_3], properties=frozenset({"normal"}))
optiondescription_8 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_1], properties=frozenset({"normal"}))
optiondescription_7 = OptionDescription(name="1", doc="1", children=[optiondescription_8])
option_6 = StrOption(name="mode_conteneur_actif1", doc="No change", default="non", properties=frozenset({"mandatory", "normal"}))
option_5 = StrOption(name="mode_conteneur_actif", doc="No change", default=Calculation(func.jinja_to_function, Params((), kwargs={'__internal_jinja': ParamValue("2.rougail.general.mode_conteneur_actif"), '__internal_type': ParamValue("string"), '__internal_multi': ParamValue(False), 'mode_conteneur_actif1': ParamOption(option_6)})), properties=frozenset({"force_default_on_freeze", "frozen", "hidden", "normal"}))
optiondescription_4 = OptionDescription(name="general", doc="general", children=[option_5, option_6], properties=frozenset({"normal"}))
optiondescription_10 = OptionDescription(name="rougail", doc="Rougail", children=[optiondescription_4], properties=frozenset({"normal"}))
optiondescription_9 = OptionDescription(name="2", doc="2", children=[optiondescription_10])
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_7, optiondescription_9])

View file

@ -0,0 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail version="0.10">
<variables>
<family name="general">
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
<value>non</value>
</variable>
<variable name="mode_conteneur_actif1" type="string" description="No change">
<value>non</value>
</variable>
</family>
</variables>
<constraints>
<fill name="{{ rougail.general.mode_conteneur_actif1 }}" type="jinja">
<target>mode_conteneur_actif</target>
</fill>
</constraints>
</rougail>

View file

@ -0,0 +1,23 @@
version: '0.10'
variables:
- family:
- name: general
variables:
- variable:
- name: mode_conteneur_actif
type: string
description: No change
hidden: true
value:
- text: non
- name: mode_conteneur_actif1
type: string
description: No change
value:
- text: non
constraints:
- fill:
- name: '{{ mode_conteneur_actif1 }}'
type: jinja
target:
- text: mode_conteneur_actif

View file

@ -0,0 +1,10 @@
{
"rougail.general.mode_conteneur_actif": {
"owner": "default",
"value": "non"
},
"rougail.general.mode_conteneur_actif1": {
"owner": "default",
"value": "non"
}
}

View file

@ -0,0 +1,4 @@
{
"rougail.general.mode_conteneur_actif": "non",
"rougail.general.mode_conteneur_actif1": "non"
}

Some files were not shown because too many files have changed in this diff Show more