Compare commits
No commits in common. "c05c0b9716a0c06986a6307445328b5110021cb8" and "b05fe25db00ab194c4eff310d9c87eb74db245a4" have entirely different histories.
c05c0b9716
...
b05fe25db0
|
@ -53,38 +53,6 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||||
return
|
return
|
||||||
self.objectspace = objectspace
|
self.objectspace = objectspace
|
||||||
self.convert_variable()
|
self.convert_variable()
|
||||||
self.convert_test()
|
|
||||||
|
|
||||||
def convert_variable(self):
|
|
||||||
"""convert variable
|
|
||||||
"""
|
|
||||||
for families in self.objectspace.space.variables.values():
|
|
||||||
families.doc = families.name
|
|
||||||
families.path = families.name
|
|
||||||
for family in families.family.values():
|
|
||||||
if not hasattr(family, 'description'):
|
|
||||||
family.description = family.name
|
|
||||||
for key, value in RENAME_ATTIBUTES.items():
|
|
||||||
setattr(family, value, getattr(family, key))
|
|
||||||
setattr(family, key, None)
|
|
||||||
family.name = normalize_family(family.name)
|
|
||||||
if not hasattr(family, 'variable'):
|
|
||||||
continue
|
|
||||||
for variable in family.variable.values():
|
|
||||||
if isinstance(variable, self.objectspace.leadership):
|
|
||||||
# first variable is a leader, others are follower
|
|
||||||
variable_type = 'leader'
|
|
||||||
for follower in variable.variable:
|
|
||||||
self._convert_variable(families.name,
|
|
||||||
follower,
|
|
||||||
variable_type,
|
|
||||||
)
|
|
||||||
variable_type = 'follower'
|
|
||||||
else:
|
|
||||||
self._convert_variable(families.name,
|
|
||||||
variable,
|
|
||||||
'variable',
|
|
||||||
)
|
|
||||||
|
|
||||||
def _convert_variable(self,
|
def _convert_variable(self,
|
||||||
namespace: str,
|
namespace: str,
|
||||||
|
@ -145,33 +113,33 @@ class VariableAnnotator: # pylint: disable=R0903
|
||||||
self.objectspace.space.constraints.check.append(check)
|
self.objectspace.space.constraints.check.append(check)
|
||||||
variable.type = 'string'
|
variable.type = 'string'
|
||||||
|
|
||||||
def convert_test(self):
|
def convert_variable(self):
|
||||||
"""Convert variable tests value
|
"""convert variable
|
||||||
"""
|
"""
|
||||||
for families in self.objectspace.space.variables.values():
|
for families in self.objectspace.space.variables.values():
|
||||||
|
families.doc = families.name
|
||||||
|
families.path = families.name
|
||||||
for family in families.family.values():
|
for family in families.family.values():
|
||||||
|
if not hasattr(family, 'description'):
|
||||||
|
family.description = family.name
|
||||||
|
for key, value in RENAME_ATTIBUTES.items():
|
||||||
|
setattr(family, value, getattr(family, key))
|
||||||
|
setattr(family, key, None)
|
||||||
|
family.name = normalize_family(family.name)
|
||||||
if not hasattr(family, 'variable'):
|
if not hasattr(family, 'variable'):
|
||||||
continue
|
continue
|
||||||
for variable in family.variable.values():
|
for variable in family.variable.values():
|
||||||
if isinstance(variable, self.objectspace.leadership):
|
if isinstance(variable, self.objectspace.leadership):
|
||||||
|
# first variable is a leader, others are follower
|
||||||
|
variable_type = 'leader'
|
||||||
for follower in variable.variable:
|
for follower in variable.variable:
|
||||||
self._convert_test(follower)
|
self._convert_variable(families.name,
|
||||||
|
follower,
|
||||||
|
variable_type,
|
||||||
|
)
|
||||||
|
variable_type = 'follower'
|
||||||
else:
|
else:
|
||||||
self._convert_test(variable)
|
self._convert_variable(families.name,
|
||||||
|
variable,
|
||||||
def _convert_test(self,
|
'variable',
|
||||||
variable,
|
)
|
||||||
) -> None:
|
|
||||||
if hasattr(variable, 'test'):
|
|
||||||
if not variable.test:
|
|
||||||
del variable.test
|
|
||||||
return
|
|
||||||
values = variable.test.split('|')
|
|
||||||
new_values = []
|
|
||||||
for value in values:
|
|
||||||
if value == '':
|
|
||||||
value = None
|
|
||||||
else:
|
|
||||||
value = CONVERT_OPTION.get(variable.type, {}).get('func', str)(value)
|
|
||||||
new_values.append(value)
|
|
||||||
variable.test = tuple(new_values)
|
|
||||||
|
|
|
@ -141,11 +141,6 @@ class RougailObjSpace:
|
||||||
):
|
):
|
||||||
"""Parses a Rougail XML file and populates the RougailObjSpace
|
"""Parses a Rougail XML file and populates the RougailObjSpace
|
||||||
"""
|
"""
|
||||||
if namespace in ['services', Config['variable_namespace']]:
|
|
||||||
msg = _(f'Namespace name "{namespace}" is not allowed in "{xmlfile}"')
|
|
||||||
raise DictConsistencyError(msg, 21)
|
|
||||||
if not namespace:
|
|
||||||
namespace = Config['variable_namespace']
|
|
||||||
redefine_variables = []
|
redefine_variables = []
|
||||||
self._xml_parse(xmlfile,
|
self._xml_parse(xmlfile,
|
||||||
document,
|
document,
|
||||||
|
|
|
@ -6,8 +6,7 @@ Sample usage::
|
||||||
|
|
||||||
>>> from rougail import Rougail
|
>>> from rougail import Rougail
|
||||||
>>> rougail = Rougail('/usr/share/rougail/rougail.dtd')
|
>>> rougail = Rougail('/usr/share/rougail/rougail.dtd')
|
||||||
>>> rougail.create_or_populate_from_xml(['/usr/share/rougail/dicos'])
|
>>> rougail.create_or_populate_from_xml('rougail', ['/usr/share/rougail/dicos'])
|
||||||
>>> rougail.create_or_populate_from_xml(['/usr/share/rougail/extra1'], 'extra1')
|
|
||||||
>>> rougail.space_visitor('/usr/share/rougail/funcs.py')
|
>>> rougail.space_visitor('/usr/share/rougail/funcs.py')
|
||||||
>>> tiramisu = rougail.save()
|
>>> tiramisu = rougail.save()
|
||||||
|
|
||||||
|
@ -40,8 +39,8 @@ class Rougail:
|
||||||
self.funcs_path = None
|
self.funcs_path = None
|
||||||
|
|
||||||
def create_or_populate_from_xml(self,
|
def create_or_populate_from_xml(self,
|
||||||
|
namespace: str,
|
||||||
xmlfolders: List[str],
|
xmlfolders: List[str],
|
||||||
namespace: str=None,
|
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
"""Parses a bunch of XML files and populates the RougailObjSpace
|
"""Parses a bunch of XML files and populates the RougailObjSpace
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -298,6 +298,12 @@ class Variable(Common):
|
||||||
for key in self.get_attributes(self.elt):
|
for key in self.get_attributes(self.elt):
|
||||||
value = getattr(self.elt, key)
|
value = getattr(self.elt, key)
|
||||||
if key in FORCE_INFORMATIONS:
|
if key in FORCE_INFORMATIONS:
|
||||||
|
if key == 'test': # pragma: no cover
|
||||||
|
value = value.split('|')
|
||||||
|
if self.object_type == 'IntOption':
|
||||||
|
value = [int(v) for v in value]
|
||||||
|
elif self.object_type == 'FloatOption':
|
||||||
|
value = [float(v) for v in value]
|
||||||
self.informations[key] = value
|
self.informations[key] = value
|
||||||
else:
|
else:
|
||||||
self.attrib[key] = value
|
self.attrib[key] = value
|
||||||
|
|
|
@ -13,7 +13,7 @@ except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
from rougail.tiramisu import ConvertDynOptionDescription
|
from rougail.tiramisu import ConvertDynOptionDescription
|
||||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='non')
|
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='non')
|
||||||
option_3.impl_set_information("test", ('test',))
|
option_3.impl_set_information("test", ['test'])
|
||||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3])
|
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3])
|
||||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
||||||
|
|
|
@ -13,7 +13,7 @@ except:
|
||||||
from tiramisu import *
|
from tiramisu import *
|
||||||
from rougail.tiramisu import ConvertDynOptionDescription
|
from rougail.tiramisu import ConvertDynOptionDescription
|
||||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='non')
|
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='non')
|
||||||
option_3.impl_set_information("test", ('test1', 'test2'))
|
option_3.impl_set_information("test", ['test1', 'test2'])
|
||||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3])
|
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3])
|
||||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="general">
|
|
||||||
<variable name="mode_conteneur_actif" test="|test1|test2">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1 +0,0 @@
|
||||||
{"rougail.general.mode_conteneur_actif": "non"}
|
|
|
@ -1,19 +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 tiramisu3 import *
|
|
||||||
except:
|
|
||||||
from tiramisu import *
|
|
||||||
from rougail.tiramisu import ConvertDynOptionDescription
|
|
||||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='non')
|
|
||||||
option_3.impl_set_information("test", (None, 'test1', 'test2'))
|
|
||||||
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])
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="general">
|
|
||||||
<variable name="mode_conteneur_actif" test="test">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="general">
|
|
||||||
<variable name="mode_conteneur_actif" redefine="True" test="test1"/>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1 +0,0 @@
|
||||||
{"rougail.general.mode_conteneur_actif": "non"}
|
|
|
@ -1,19 +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 tiramisu3 import *
|
|
||||||
except:
|
|
||||||
from tiramisu import *
|
|
||||||
from rougail.tiramisu import ConvertDynOptionDescription
|
|
||||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='non')
|
|
||||||
option_3.impl_set_information("test", ('test1',))
|
|
||||||
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])
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="general">
|
|
||||||
<variable name="mode_conteneur_actif" test="test">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="general">
|
|
||||||
<variable name="mode_conteneur_actif" redefine="True" test=""/>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1 +0,0 @@
|
||||||
{"rougail.general.mode_conteneur_actif": "non"}
|
|
|
@ -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 tiramisu3 import *
|
|
||||||
except:
|
|
||||||
from tiramisu import *
|
|
||||||
from rougail.tiramisu import ConvertDynOptionDescription
|
|
||||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='mode_conteneur_actif', multi=False, default='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])
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="général">
|
|
||||||
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
<variable name="activer_ejabberd" type="string" description="No change" hidden="True">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?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>
|
|
|
@ -1,15 +0,0 @@
|
||||||
<?xml version='1.0' encoding='UTF-8'?>
|
|
||||||
<rougail>
|
|
||||||
<variables>
|
|
||||||
<family name="général">
|
|
||||||
<variable name="mode_conteneur_actif" type="string" description="No change" hidden="True">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
<variable name="activer_ejabberd" type="string" description="No change" hidden="True">
|
|
||||||
<value>non</value>
|
|
||||||
</variable>
|
|
||||||
</family>
|
|
||||||
</variables>
|
|
||||||
</rougail>
|
|
||||||
<!-- vim: ts=4 sw=4 expandtab
|
|
||||||
-->
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?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>
|
|
|
@ -60,14 +60,13 @@ def launch_flattener(test_dir, test_ok=False):
|
||||||
subfolder = join(test_dir, 'subfolder')
|
subfolder = join(test_dir, 'subfolder')
|
||||||
if isdir(subfolder):
|
if isdir(subfolder):
|
||||||
dirs.append(subfolder)
|
dirs.append(subfolder)
|
||||||
eolobj.create_or_populate_from_xml(dirs)
|
eolobj.create_or_populate_from_xml(Config['variable_namespace'], dirs)
|
||||||
if isdir(join(test_dir, 'extra_dirs')):
|
subfolder = join(test_dir, 'extra_dirs', 'extra')
|
||||||
extras = listdir(join(test_dir, 'extra_dirs'))
|
if isdir(subfolder):
|
||||||
extras.sort()
|
eolobj.create_or_populate_from_xml('extra', [subfolder])
|
||||||
for extra in extras:
|
subfolder = join(test_dir, 'extra_dirs', 'extra1')
|
||||||
subfolder = join(test_dir, 'extra_dirs', extra)
|
if isdir(subfolder):
|
||||||
if isdir(subfolder):
|
eolobj.create_or_populate_from_xml('extra1', [subfolder])
|
||||||
eolobj.create_or_populate_from_xml([subfolder], extra)
|
|
||||||
eosfunc = join(dico_dirs, '../eosfunc/test.py')
|
eosfunc = join(dico_dirs, '../eosfunc/test.py')
|
||||||
Config['patch_dir'] = join(test_dir, 'patches')
|
Config['patch_dir'] = join(test_dir, 'patches')
|
||||||
eolobj.space_visitor(eosfunc)
|
eolobj.space_visitor(eosfunc)
|
||||||
|
|
Loading…
Reference in New Issue