valid value in param

This commit is contained in:
Emmanuel Garette 2021-02-17 17:30:06 +01:00
parent c11ae16ea0
commit 3b2d96566b
10 changed files with 68 additions and 5 deletions

View file

@ -24,6 +24,8 @@ 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
"""
import tiramisu
from .variable import CONVERT_OPTION
from ..i18n import _
@ -104,9 +106,11 @@ class ParamAnnotator:
f'with type "{variable_type}"')
raise DictConsistencyError(msg, 7, param.xmlfiles)
try:
param.text = CONVERT_OPTION[variable_type].get('func', str)(param.text)
option = CONVERT_OPTION[variable_type]
param.text = option.get('func', str)(param.text)
getattr(tiramisu, option['opttype'])('test', 'Object to valid value', param.text, **option.get('initkwargs', {}))
except ValueError as err:
msg = _(f'unable to change type of "{param.text}" '
msg = _(f'unable to change type of value "{param.text}" '
f'is not a valid "{variable_type}"')
raise DictConsistencyError(msg, 13, param.xmlfiles) from err
param.type = variable_type

View file

@ -17,7 +17,6 @@
<constraints>
<condition name="disabled_if_in" source="my_variable">
<param type='nil'/>
<param></param>
<target type="portlist">example</target>
</condition>
</constraints>

View file

@ -15,11 +15,11 @@ option_2 = PortOption(name="my_variable", doc="my_variable", default="123", allo
option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2])
option_7 = SymLinkOption(name="name", opt=option_2)
option_8 = StrOption(name="protocol", doc="protocol", default="udp")
option_9 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue((None, '')), 'condition_operator': ParamValue("OR")})))
option_9 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue(None)})))
option_6 = OptionDescription(name="my_variable", doc="my_variable", children=[option_7, option_8, option_9])
option_11 = SymLinkOption(name="name", opt=option_2)
option_12 = StrOption(name="protocol", doc="protocol", default="tcp")
option_13 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue((None, '')), 'condition_operator': ParamValue("OR")})))
option_13 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue(None)})))
option_10 = OptionDescription(name="my_variable_1", doc="my_variable_1", children=[option_11, option_12, option_13])
option_5 = OptionDescription(name="ports", doc="ports", children=[option_6, option_10])
option_4 = OptionDescription(name="ntp", doc="ntp", children=[option_5])

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<rougail>
<variables>
<variable name='my_variable' type='port'>
<value>123</value>
</variable>
</variables>
<constraints>
<condition name="disabled_if_in" source="my_variable">
<param type='nil'/>
<target type="portlist" optional="True">example</target>
</condition>
</constraints>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->

View file

@ -0,0 +1 @@
{"rougail.my_variable": "123"}

View file

@ -0,0 +1,16 @@
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 *
option_2 = PortOption(name="my_variable", doc="my_variable", default="123", allow_private=True, properties=frozenset({"mandatory", "normal"}))
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,26 @@
<?xml version="1.0" encoding="utf-8"?>
<rougail>
<services>
<service name='ntp'>
<port protocol='udp' port_type="variable" portlist="example">my_variable</port>
<port protocol='tcp' port_type="variable" portlist="example">my_variable</port>
</service>
</services>
<variables>
<variable name='my_variable' type='port'>
<value>123</value>
</variable>
</variables>
<constraints>
<condition name="disabled_if_in" source="my_variable">
<param type='nil'/>
<param>aaa</param>
<target type="portlist">example</target>
</condition>
</constraints>
</rougail>
<!-- vim: ts=4 sw=4 expandtab
-->