family and var with same name

This commit is contained in:
Emmanuel Garette 2020-11-11 16:59:44 +01:00
parent 3d49f2fe8c
commit 5a45885ed8
12 changed files with 111 additions and 14 deletions

View File

@ -13,7 +13,8 @@ class Path:
def __init__(self):
self.variables = {}
self.families = {}
self.full_paths = {}
self.full_paths_families = {}
self.full_paths_variables = {}
# Family
def add_family(self,
@ -23,7 +24,7 @@ class Path:
) -> str: # pylint: disable=C0111
if '.' not in name and namespace == Config['variable_namespace']:
full_name = '.'.join([namespace, name])
self.full_paths[name] = full_name
self.full_paths_families[name] = full_name
else:
full_name = name
if full_name in self.families and self.families[full_name]['variableobj'] != variableobj:
@ -41,8 +42,8 @@ class Path:
check_name=False,
allow_dot=True,
)
if '.' not in name and current_namespace == Config['variable_namespace'] and name in self.full_paths:
name = self.full_paths[name]
if '.' not in name and current_namespace == Config['variable_namespace'] and name in self.full_paths_families:
name = self.full_paths_families[name]
if current_namespace is None: # pragma: no cover
raise OperationError('current_namespace must not be None')
dico = self.families[name]
@ -55,8 +56,8 @@ class Path:
def get_family_obj(self,
name: str,
) -> 'Family': # pylint: disable=C0111
if '.' not in name and name in self.full_paths:
name = self.full_paths[name]
if '.' not in name and name in self.full_paths_families:
name = self.full_paths_families[name]
if name not in self.families:
raise DictConsistencyError(_('unknown family {}').format(name))
dico = self.families[name]
@ -65,7 +66,7 @@ class Path:
def family_is_defined(self,
name: str,
) -> str: # pylint: disable=C0111
if '.' not in name and name not in self.families and name in self.full_paths:
if '.' not in name and name not in self.families and name in self.full_paths_families:
return True
return name in self.families
@ -88,7 +89,7 @@ class Path:
dico['variableobj'],
)
if namespace == Config['variable_namespace']:
self.full_paths[name] = new_path
self.full_paths_variables[name] = new_path
else:
name = new_path
dico = self._get_variable(name)
@ -110,7 +111,7 @@ class Path:
) -> str: # pylint: disable=C0111
if '.' not in name:
full_name = '.'.join([namespace, family, name])
self.full_paths[name] = full_name
self.full_paths_variables[name] = full_name
else:
full_name = name
if namespace == Config['variable_namespace']:
@ -176,7 +177,7 @@ class Path:
def path_is_defined(self,
name: str,
) -> str: # pylint: disable=C0111
if '.' not in name and name not in self.variables and name in self.full_paths:
if '.' not in name and name not in self.variables and name in self.full_paths_variables:
return True
return name in self.variables
@ -186,8 +187,8 @@ class Path:
) -> str:
if name not in self.variables:
if name not in self.variables:
if '.' not in name and name in self.full_paths:
name = self.full_paths[name]
if '.' not in name and name in self.full_paths_variables:
name = self.full_paths_variables[name]
if name not in self.variables:
for var_name, variable in self.variables.items():
if variable['is_dynamic'] and name.startswith(var_name):
@ -195,9 +196,9 @@ class Path:
raise Exception('This option is dynamic, should use "with_suffix" attribute')
return variable, name[len(var_name):]
if '.' not in name:
for var_name, path in self.full_paths.items():
for var_name, path in self.full_paths_variables.items():
if name.startswith(var_name):
variable = self.variables[self.full_paths[var_name]]
variable = self.variables[self.full_paths_variables[var_name]]
if variable['is_dynamic']:
if not with_suffix:
raise Exception('This option is dynamic, should use "with_suffix" attribute')

View File

@ -0,0 +1,12 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<variables>
<family name="general">
<variable name="general" type="oui/non" description="description">
<value>non</value>
</variable>
</family>
</variables>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

View File

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

View File

@ -0,0 +1,14 @@
import imp
func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py')
for key, value in dict(locals()).items():
if key != ['imp', 'func']:
setattr(func, key, value)
try:
from tiramisu3 import *
except:
from tiramisu import *
from rougail.tiramisu import ConvertDynOptionDescription
option_3 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='general', doc='description', multi=False, default='non', values=('oui', 'non'))
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])

View File

@ -0,0 +1,25 @@
<?xml version='1.0' encoding='UTF-8'?>
<rougail>
<services/>
<variables>
<family name="extra">
<variable name="mode_conteneur_actif" type="oui/non" description="No change" hidden="True">
<value>non</value>
</variable>
<variable name="activer_ejabberd" type="oui/non" description="No change" hidden="True">
<value>non</value>
</variable>
</family>
<separators/>
</variables>
<constraints>
</constraints>
<help/>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<rougail>
<variables>
<family name='ejabberd'>
<variable name="description" type="string">
<value>Exportation de la base de ejabberd</value>
</variable>
<variable name="day" type="schedule"></variable>
<variable name="mode" type="schedulemod">
<value>pre</value>
</variable>
</family>
</variables>
<constraints>
<fill name='calc_multi_condition' target='extra.ejabberd.day'>
<param>non</param>
<param type='variable' name='condition_1' notraisepropertyerror='True'>activer_ejabberd</param>
<param name='match'>none</param>
<param name='mismatch'>daily</param>
</fill>
</constraints>
</rougail>

View File

@ -0,0 +1 @@
{"rougail.extra.mode_conteneur_actif": "non", "rougail.extra.activer_ejabberd": "non", "extra.ejabberd.description": "Exportation de la base de ejabberd", "extra.ejabberd.day": null, "extra.ejabberd.mode": "pre"}

View File

@ -0,0 +1,20 @@
import imp
func = imp.load_source('func', 'tests/dictionaries/../eosfunc/test.py')
for key, value in dict(locals()).items():
if key != ['imp', 'func']:
setattr(func, key, value)
try:
from tiramisu3 import *
except:
from tiramisu import *
from rougail.tiramisu import ConvertDynOptionDescription
option_3 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_4 = ChoiceOption(properties=frozenset({'force_default_on_freeze', 'frozen', 'hidden', 'mandatory', 'normal'}), name='activer_ejabberd', doc='No change', multi=False, default='non', values=('oui', 'non'))
option_2 = OptionDescription(name='extra', doc='extra', properties=frozenset({'normal'}), children=[option_3, option_4])
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
option_7 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='description', doc='description', multi=False, default='Exportation de la base de ejabberd')
option_8 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='day', doc='day', multi=False, default=Calculation(func.calc_multi_condition, Params((ParamValue("non")), kwargs={'condition_1': ParamOption(option_4, notraisepropertyerror=True, todict=False), 'match': ParamValue("none"), 'mismatch': ParamValue("daily")})), values=('none', 'daily', 'weekly', 'monthly'))
option_9 = ChoiceOption(properties=frozenset({'mandatory', 'normal'}), name='mode', doc='mode', multi=False, default='pre', values=('pre', 'post'))
option_6 = OptionDescription(name='ejabberd', doc='ejabberd', properties=frozenset({'normal'}), children=[option_7, option_8, option_9])
option_5 = OptionDescription(name='extra', doc='extra', children=[option_6])
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1, option_5])