Compare commits
4 Commits
pkg/dev/ri
...
19d9fdc705
Author | SHA1 | Date | |
---|---|---|---|
19d9fdc705 | |||
d5129d6fe7 | |||
11294fdd61 | |||
6bda645903 |
@ -34,6 +34,33 @@ def mode_factory():
|
||||
modes = mode_factory()
|
||||
|
||||
|
||||
CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
|
||||
'float': dict(opttype="FloatOption", func=float),
|
||||
'choice': dict(opttype="ChoiceOption"),
|
||||
'string': dict(opttype="StrOption"),
|
||||
'password': dict(opttype="PasswordOption"),
|
||||
'mail': dict(opttype="EmailOption"),
|
||||
'boolean': dict(opttype="BoolOption"),
|
||||
'symlink': dict(opttype="SymLinkOption"),
|
||||
'filename': dict(opttype="FilenameOption"),
|
||||
'date': dict(opttype="DateOption"),
|
||||
'unix_user': dict(opttype="UsernameOption"),
|
||||
'ip': dict(opttype="IPOption", initkwargs={'allow_reserved': True}),
|
||||
'local_ip': dict(opttype="IPOption", initkwargs={'private_only': True, 'warnings_only': True}),
|
||||
'netmask': dict(opttype="NetmaskOption"),
|
||||
'network': dict(opttype="NetworkOption"),
|
||||
'broadcast': dict(opttype="BroadcastOption"),
|
||||
'netbios': dict(opttype="DomainnameOption", initkwargs={'type': 'netbios', 'warnings_only': True}),
|
||||
'domain': dict(opttype="DomainnameOption", initkwargs={'type': 'domainname', 'allow_ip': False}),
|
||||
'hostname': dict(opttype="DomainnameOption", initkwargs={'type': 'hostname', 'allow_ip': False}),
|
||||
'web_address': dict(opttype="URLOption", initkwargs={'allow_ip': True, 'allow_without_dot': True}),
|
||||
'port': dict(opttype="PortOption", initkwargs={'allow_private': True}),
|
||||
'mac': dict(opttype="MACOption"),
|
||||
'cidr': dict(opttype="IPOption", initkwargs={'cidr': True}),
|
||||
'network_cidr': dict(opttype="NetworkOption", initkwargs={'cidr': True}),
|
||||
}
|
||||
|
||||
|
||||
# a CreoleObjSpace's attribute has some annotations
|
||||
# that shall not be present in the exported (flatened) XML
|
||||
ERASED_ATTRIBUTES = ('redefine', 'exists', 'fallback', 'optional', 'remove_check', 'namespace',
|
||||
@ -56,8 +83,6 @@ KEY_TYPE = {'variable': 'symlink',
|
||||
'URLOption': 'web_address',
|
||||
'FilenameOption': 'filename'}
|
||||
|
||||
CONVERSION = {'number': int}
|
||||
|
||||
FREEZE_AUTOFREEZE_VARIABLE = 'module_instancie'
|
||||
|
||||
PROPERTIES = ('hidden', 'frozen', 'auto_freeze', 'auto_save', 'force_default_on_freeze',
|
||||
@ -108,7 +133,7 @@ class GroupAnnotator:
|
||||
self.manage_follower(namespace,
|
||||
leader_family_name,
|
||||
variable,
|
||||
leader_name,
|
||||
leadership_name,
|
||||
follower_names,
|
||||
leader_space,
|
||||
leader_is_hidden,
|
||||
@ -126,8 +151,13 @@ class GroupAnnotator:
|
||||
# leader_is_hidden = True
|
||||
else:
|
||||
leader_space = self.objectspace.Leadership(variable.xmlfiles)
|
||||
if hasattr(group, 'name'):
|
||||
leadership_name = group.name
|
||||
else:
|
||||
leadership_name = leader_name
|
||||
leader_is_hidden = self.manage_leader(leader_space,
|
||||
leader_family_name,
|
||||
leadership_name,
|
||||
leader_name,
|
||||
namespace,
|
||||
variable,
|
||||
@ -142,6 +172,7 @@ class GroupAnnotator:
|
||||
def manage_leader(self,
|
||||
leader_space: 'Leadership',
|
||||
leader_family_name: str,
|
||||
leadership_name: str,
|
||||
leader_name: str,
|
||||
namespace: str,
|
||||
variable: 'Variable',
|
||||
@ -152,7 +183,7 @@ class GroupAnnotator:
|
||||
if variable.multi is not True:
|
||||
raise DictConsistencyError(_('the variable {} in a group must be multi').format(variable.name))
|
||||
leader_space.variable = []
|
||||
leader_space.name = leader_name
|
||||
leader_space.name = leadership_name
|
||||
leader_space.hidden = variable.hidden
|
||||
if variable.hidden:
|
||||
leader_is_hidden = True
|
||||
@ -167,9 +198,9 @@ class GroupAnnotator:
|
||||
leader_space.doc = variable.description
|
||||
else:
|
||||
leader_space.doc = variable.name
|
||||
leader_path = namespace + '.' + leader_family_name + '.' + leader_name
|
||||
leadership_path = namespace + '.' + leader_family_name + '.' + leadership_name
|
||||
self.objectspace.paths.add_family(namespace,
|
||||
leader_path,
|
||||
leadership_path,
|
||||
leader_space,
|
||||
)
|
||||
leader_family = self.objectspace.space.variables[namespace].family[leader_family_name]
|
||||
@ -459,7 +490,7 @@ class VariableAnnotator:
|
||||
for value in variable.value:
|
||||
if not hasattr(value, 'type'):
|
||||
value.type = variable.type
|
||||
value.name = CONVERSION.get(value.type, str)(value.name)
|
||||
value.name = CONVERT_OPTION.get(value.type, {}).get('func', str)(value.name)
|
||||
for key, value in RENAME_ATTIBUTES.items():
|
||||
setattr(variable, value, getattr(variable, key))
|
||||
setattr(variable, key, None)
|
||||
@ -491,6 +522,11 @@ class VariableAnnotator:
|
||||
self.objectspace.space.constraints.check.append(check)
|
||||
variable.type = 'string'
|
||||
|
||||
def _valid_type(variable):
|
||||
if variable.type not in CONVERT_OPTION:
|
||||
xmlfiles = self.objectspace.display_xmlfiles(variable.xmlfiles)
|
||||
raise DictConsistencyError(_(f'unvalid type "{variable.type}" for variable "{variable.name}" in {xmlfiles}'))
|
||||
|
||||
if not hasattr(self.objectspace.space, 'variables'):
|
||||
return
|
||||
for families in self.objectspace.space.variables.values():
|
||||
@ -520,6 +556,7 @@ class VariableAnnotator:
|
||||
follower,
|
||||
path,
|
||||
)
|
||||
_valid_type(follower)
|
||||
else:
|
||||
path = '{}.{}.{}'.format(namespace, normalize_family(family.name), variable.name)
|
||||
_convert_variable(variable,
|
||||
@ -529,6 +566,7 @@ class VariableAnnotator:
|
||||
variable,
|
||||
path,
|
||||
)
|
||||
_valid_type(variable)
|
||||
|
||||
def convert_helps(self):
|
||||
if not hasattr(self.objectspace.space, 'help'):
|
||||
@ -935,7 +973,7 @@ class ConstraintAnnotator:
|
||||
choice = self.objectspace.choice(variable.xmlfiles)
|
||||
try:
|
||||
if value is not None:
|
||||
choice.name = CONVERSION.get(type_, str)(value)
|
||||
choice.name = CONVERT_OPTION[type_].get('func', str)(value)
|
||||
else:
|
||||
choice.name = value
|
||||
except:
|
||||
@ -950,7 +988,7 @@ class ConstraintAnnotator:
|
||||
for value in variable.value:
|
||||
value.type = type_
|
||||
try:
|
||||
cvalue = CONVERSION.get(type_, str)(value.name)
|
||||
cvalue = CONVERT_OPTION[type_].get('func', str)(value.name)
|
||||
except:
|
||||
raise DictConsistencyError(_(f'unable to change type of value "{value}" is not a valid "{type_}" for "{variable.name}"'))
|
||||
if cvalue not in choices:
|
||||
|
@ -131,6 +131,7 @@
|
||||
|
||||
<!ELEMENT group (follower+)>
|
||||
<!ATTLIST group leader CDATA #REQUIRED>
|
||||
<!ATTLIST group name CDATA #IMPLIED>
|
||||
<!ATTLIST group description CDATA #IMPLIED>
|
||||
|
||||
<!ELEMENT param (#PCDATA)>
|
||||
|
@ -4,7 +4,7 @@ flattened XML specific
|
||||
from .config import Config
|
||||
from .i18n import _
|
||||
from .error import LoaderError
|
||||
from .annotator import ERASED_ATTRIBUTES
|
||||
from .annotator import ERASED_ATTRIBUTES, CONVERT_OPTION
|
||||
|
||||
|
||||
FUNC_TO_DICT = ['valid_not_equal']
|
||||
@ -12,32 +12,6 @@ FORCE_INFORMATIONS = ['help', 'test', 'separator', 'manage']
|
||||
ATTRIBUTES_ORDER = ('name', 'doc', 'default', 'multi')
|
||||
|
||||
|
||||
CONVERT_OPTION = {'number': dict(opttype="IntOption", func=int),
|
||||
'choice': dict(opttype="ChoiceOption"),
|
||||
'string': dict(opttype="StrOption"),
|
||||
'password': dict(opttype="PasswordOption"),
|
||||
'mail': dict(opttype="EmailOption"),
|
||||
'boolean': dict(opttype="BoolOption"),
|
||||
'symlink': dict(opttype="SymLinkOption"),
|
||||
'filename': dict(opttype="FilenameOption"),
|
||||
'date': dict(opttype="DateOption"),
|
||||
'unix_user': dict(opttype="UsernameOption"),
|
||||
'ip': dict(opttype="IPOption", initkwargs={'allow_reserved': True}),
|
||||
'local_ip': dict(opttype="IPOption", initkwargs={'private_only': True, 'warnings_only': True}),
|
||||
'netmask': dict(opttype="NetmaskOption"),
|
||||
'network': dict(opttype="NetworkOption"),
|
||||
'broadcast': dict(opttype="BroadcastOption"),
|
||||
'netbios': dict(opttype="DomainnameOption", initkwargs={'type': 'netbios', 'warnings_only': True}),
|
||||
'domain': dict(opttype="DomainnameOption", initkwargs={'type': 'domainname', 'allow_ip': False}),
|
||||
'hostname': dict(opttype="DomainnameOption", initkwargs={'type': 'hostname', 'allow_ip': False}),
|
||||
'web_address': dict(opttype="URLOption", initkwargs={'allow_ip': True, 'allow_without_dot': True}),
|
||||
'port': dict(opttype="PortOption", initkwargs={'allow_private': True}),
|
||||
'mac': dict(opttype="MACOption"),
|
||||
'cidr': dict(opttype="IPOption", initkwargs={'cidr': True}),
|
||||
'network_cidr': dict(opttype="NetworkOption", initkwargs={'cidr': True}),
|
||||
}
|
||||
|
||||
|
||||
class TiramisuReflector:
|
||||
def __init__(self,
|
||||
xmlroot,
|
||||
@ -344,6 +318,8 @@ class Variable(Common):
|
||||
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
|
||||
else:
|
||||
self.attrib[key] = value
|
||||
@ -443,7 +419,7 @@ class Variable(Common):
|
||||
self.attrib['default'].append(value)
|
||||
if not self.is_leader:
|
||||
self.attrib['default_multi'] = value
|
||||
elif isinstance(value, int):
|
||||
elif isinstance(value, (int, float)):
|
||||
self.attrib['default'].append(value)
|
||||
else:
|
||||
self.attrib['default'].append("'" + value + "'")
|
||||
|
16
tests/dictionaries/01base_float/00-base.xml
Normal file
16
tests/dictionaries/01base_float/00-base.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<variables>
|
||||
<family name="general">
|
||||
<variable name="float" type="float" description="Description">
|
||||
<value>0.527</value>
|
||||
</variable>
|
||||
<variable name="float_multi" type="float" description="Description" multi="True">
|
||||
<value>0.527</value>
|
||||
</variable>
|
||||
</family>
|
||||
<separators/>
|
||||
</variables>
|
||||
</rougail>
|
||||
<!-- vim: ts=4 sw=4 expandtab
|
||||
-->
|
0
tests/dictionaries/01base_float/__init__.py
Normal file
0
tests/dictionaries/01base_float/__init__.py
Normal file
1
tests/dictionaries/01base_float/makedict/base.json
Normal file
1
tests/dictionaries/01base_float/makedict/base.json
Normal file
@ -0,0 +1 @@
|
||||
{"rougail.general.float": 0.527, "rougail.general.float_multi": [0.527]}
|
15
tests/dictionaries/01base_float/tiramisu/base.py
Normal file
15
tests/dictionaries/01base_float/tiramisu/base.py
Normal file
@ -0,0 +1,15 @@
|
||||
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 = FloatOption(properties=frozenset({'mandatory', 'normal'}), name='float', doc='Description', multi=False, default=0.527)
|
||||
option_4 = FloatOption(properties=frozenset({'mandatory', 'normal'}), name='float_multi', doc='Description', multi=True, default=[0.527], default_multi=0.527)
|
||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4])
|
||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
27
tests/dictionaries/10load_leadership_name/00-base.xml
Normal file
27
tests/dictionaries/10load_leadership_name/00-base.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rougail>
|
||||
<variables>
|
||||
<family name='general'>
|
||||
<variable name='mode_conteneur_actif' type='oui/non' description="No change">
|
||||
<value>non</value>
|
||||
</variable>
|
||||
</family>
|
||||
<family name='general1'>
|
||||
<variable name='leader' type='string' description="leader" multi="True"/>
|
||||
<variable name='follower1' type='string' description="follower1"/>
|
||||
<variable name='follower2' type='string' description="follower2"/>
|
||||
</family>
|
||||
</variables>
|
||||
<constraints>
|
||||
<fill name='calc_val' target='follower1'>
|
||||
<param name='valeur'>valfill</param>
|
||||
</fill>
|
||||
<fill name='calc_val' target='follower2'>
|
||||
<param type='variable'>follower1</param>
|
||||
</fill>
|
||||
<group leader='leader' name="other_name">
|
||||
<follower>follower1</follower>
|
||||
<follower>follower2</follower>
|
||||
</group>
|
||||
</constraints>
|
||||
</rougail>
|
@ -0,0 +1 @@
|
||||
{"rougail.general.mode_conteneur_actif": "non", "rougail.general1.other_name.leader": [], "rougail.general1.other_name.follower1": [], "rougail.general1.other_name.follower2": []}
|
19
tests/dictionaries/10load_leadership_name/tiramisu/base.py
Normal file
19
tests/dictionaries/10load_leadership_name/tiramisu/base.py
Normal file
@ -0,0 +1,19 @@
|
||||
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='mode_conteneur_actif', doc='No change', multi=False, default='non', values=('oui', 'non'))
|
||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3])
|
||||
option_6 = StrOption(name='leader', doc='leader', multi=True)
|
||||
option_7 = StrOption(properties=frozenset({'normal'}), name='follower1', doc='follower1', multi=True, default=Calculation(func.calc_val, Params((), kwargs={'valeur': ParamValue("valfill")})))
|
||||
option_8 = StrOption(properties=frozenset({'normal'}), name='follower2', doc='follower2', multi=True, default=Calculation(func.calc_val, Params((ParamOption(option_7, notraisepropertyerror=False, todict=False)), kwargs={})))
|
||||
option_5 = Leadership(name='other_name', doc='leader', properties=frozenset({'normal'}), children=[option_6, option_7, option_8])
|
||||
option_4 = OptionDescription(name='general1', doc='general1', properties=frozenset({'normal'}), children=[option_5])
|
||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2, option_4])
|
||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
10
tests/dictionaries/80unknown_type/00-base.xml
Normal file
10
tests/dictionaries/80unknown_type/00-base.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<rougail>
|
||||
<variables>
|
||||
<family name="general">
|
||||
<variable name="mode_conteneur_actif" type="unknown" description="Description"/>
|
||||
</family>
|
||||
</variables>
|
||||
</rougail>
|
||||
<!-- vim: ts=4 sw=4 expandtab
|
||||
-->
|
0
tests/dictionaries/80unknown_type/__init__.py
Normal file
0
tests/dictionaries/80unknown_type/__init__.py
Normal file
Reference in New Issue
Block a user