Compare commits
No commits in common. "2db305b1f0a4975b13db85277a41f8057789bd6f" and "baa56616bd056bce471454473e2ee352063663de" have entirely different histories.
2db305b1f0
...
baa56616bd
|
@ -1,8 +1,3 @@
|
||||||
Mon Apr 1 11:47:30 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
|
|
||||||
* version 3.0 rc16
|
|
||||||
* tiramisu is now async
|
|
||||||
* add postgresql storage
|
|
||||||
|
|
||||||
Mon Sep 2 14:10:40 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
|
Mon Sep 2 14:10:40 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||||
* version 3.0 rc15
|
* version 3.0 rc15
|
||||||
* add parents method to MetaConfig
|
* add parents method to MetaConfig
|
||||||
|
|
13
setup.py
13
setup.py
|
@ -1,17 +1,11 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from setuptools import setup
|
from setuptools import setup, find_packages
|
||||||
import os
|
import os
|
||||||
from tiramisu import __version__
|
from tiramisu import __version__
|
||||||
|
|
||||||
|
|
||||||
ORI_PACKAGE_NAME = 'tiramisu'
|
PACKAGE_NAME = os.environ.get('PACKAGE_DST', 'tiramisu')
|
||||||
PACKAGE_NAME = os.environ.get('PACKAGE_DST', ORI_PACKAGE_NAME)
|
|
||||||
|
|
||||||
if PACKAGE_NAME != ORI_PACKAGE_NAME:
|
|
||||||
package_dir = {PACKAGE_NAME: ORI_PACKAGE_NAME}
|
|
||||||
else:
|
|
||||||
package_dir = None
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
version=__version__,
|
version=__version__,
|
||||||
|
@ -46,6 +40,5 @@ producing flexible and fast options access.
|
||||||
This version requires Python 3.5 or later.
|
This version requires Python 3.5 or later.
|
||||||
""",
|
""",
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
package_dir=package_dir,
|
packages=find_packages(include=['tiramisu'])
|
||||||
packages=[PACKAGE_NAME],
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,9 +9,7 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
|
||||||
StrOption, PortOption, BroadcastOption, DomainnameOption, \
|
StrOption, PortOption, BroadcastOption, DomainnameOption, \
|
||||||
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
|
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
|
||||||
OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \
|
OptionDescription, DynOptionDescription, SynDynOption, submulti, Leadership, \
|
||||||
Config, \
|
Config, Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamIndex, Calculation, calc_value, \
|
||||||
Params, ParamOption, ParamValue, ParamSuffix, ParamSelfOption, ParamDynOption, ParamIndex, \
|
|
||||||
Calculation, calc_value, \
|
|
||||||
delete_session
|
delete_session
|
||||||
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
|
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
|
||||||
from tiramisu.storage import list_sessions
|
from tiramisu.storage import list_sessions
|
||||||
|
@ -147,8 +145,8 @@ async def test_getdoc_dyndescription():
|
||||||
assert await cfg.option('od.dodval2.stval2').option.name() == 'stval2'
|
assert await cfg.option('od.dodval2.stval2').option.name() == 'stval2'
|
||||||
assert await cfg.option('od.dodval1').option.name() == 'dodval1'
|
assert await cfg.option('od.dodval1').option.name() == 'dodval1'
|
||||||
assert await cfg.option('od.dodval2').option.name() == 'dodval2'
|
assert await cfg.option('od.dodval2').option.name() == 'dodval2'
|
||||||
assert await cfg.option('od.dodval1.stval1').option.doc() == 'doc1val1'
|
assert await cfg.option('od.dodval1.stval1').option.doc() == 'doc1'
|
||||||
assert await cfg.option('od.dodval2.stval2').option.doc() == 'doc1val2'
|
assert await cfg.option('od.dodval2.stval2').option.doc() == 'doc1'
|
||||||
assert await cfg.option('od.dodval1').option.doc() == 'doc2val1'
|
assert await cfg.option('od.dodval1').option.doc() == 'doc2val1'
|
||||||
assert await cfg.option('od.dodval2').option.doc() == 'doc2val2'
|
assert await cfg.option('od.dodval2').option.doc() == 'doc2val2'
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
@ -291,56 +289,6 @@ async def test_callback_dyndescription():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_callback_dyndescription_outside_wrong_param():
|
|
||||||
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
|
|
||||||
st = StrOption('st', '', Calculation(return_dynval))
|
|
||||||
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
|
|
||||||
out = StrOption('out', '', Calculation(return_dynval, Params(ParamOption(st))))
|
|
||||||
od = OptionDescription('od', '', [dod, out])
|
|
||||||
od2 = OptionDescription('od', '', [od, lst])
|
|
||||||
async with await Config(od2) as cfg:
|
|
||||||
with pytest.raises(ConfigError):
|
|
||||||
await cfg.value.dict()
|
|
||||||
assert not await list_sessions()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_callback_dyndescription_outside1():
|
|
||||||
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
|
|
||||||
st = StrOption('st', '', Calculation(return_dynval))
|
|
||||||
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
|
|
||||||
out = StrOption('out', '', Calculation(return_dynval, Params(ParamDynOption(st, 'val1', dod))))
|
|
||||||
od = OptionDescription('od', '', [dod, out])
|
|
||||||
od2 = OptionDescription('od', '', [od, lst])
|
|
||||||
async with await Config(od2) as cfg:
|
|
||||||
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val', 'od.dodval2.stval2': 'val', 'od.out': 'val', 'lst': ['val1', 'val2']}
|
|
||||||
await cfg.option('od.dodval1.stval1').value.set('val1')
|
|
||||||
await cfg.option('od.dodval2.stval2').value.set('val2')
|
|
||||||
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val1', 'od.dodval2.stval2': 'val2', 'od.out': 'val1', 'lst': ['val1', 'val2']}
|
|
||||||
await cfg.option('lst').value.set(['val2'])
|
|
||||||
with pytest.raises(ConfigError):
|
|
||||||
await cfg.value.dict()
|
|
||||||
await cfg.option('lst').value.set(['val1'])
|
|
||||||
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val1', 'od.out': 'val1', 'lst': ['val1']}
|
|
||||||
assert not await list_sessions()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_callback_dyndescription_outside2():
|
|
||||||
lst = StrOption('lst', '', ['val1', 'val2'], multi=True)
|
|
||||||
out = StrOption('out', '')
|
|
||||||
st = StrOption('st', '', Calculation(return_dynval, Params(ParamOption(out))))
|
|
||||||
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(lst))))
|
|
||||||
od = OptionDescription('od', '', [dod, out])
|
|
||||||
od2 = OptionDescription('od', '', [od, lst])
|
|
||||||
async with await Config(od2) as cfg:
|
|
||||||
assert await cfg.value.dict() == {'od.dodval1.stval1': None, 'od.dodval2.stval2': None, 'od.out': None, 'lst': ['val1', 'val2']}
|
|
||||||
await cfg.option('od.out').value.set('val1')
|
|
||||||
assert await cfg.value.dict() == {'od.dodval1.stval1': 'val1', 'od.dodval2.stval2': 'val1', 'od.out': 'val1', 'lst': ['val1', 'val2']}
|
|
||||||
assert not await list_sessions()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_callback_list_dyndescription():
|
async def test_callback_list_dyndescription():
|
||||||
st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',))
|
st = StrOption('st', '', Calculation(return_list2, Params(ParamSuffix())), multi=True, properties=('notunique',))
|
||||||
|
|
|
@ -187,6 +187,26 @@ async def test_force_store_value():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_force_store_value_leadership_follower():
|
||||||
|
b = IntOption('int', 'Test int option', multi=True)
|
||||||
|
c = StrOption('str', 'Test string option', multi=True, properties=('force_store_value',))
|
||||||
|
descr = Leadership("int", "", [b, c])
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
cfg = await Config(descr, session_id='error')
|
||||||
|
await delete_session('error')
|
||||||
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
#@pytest.mark.asyncio
|
||||||
|
#async def test_force_store_value_leadership():
|
||||||
|
# b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||||
|
# c = StrOption('str', 'Test string option', multi=True)
|
||||||
|
# descr = Leadership("int", "", [b, c])
|
||||||
|
# cfg = await Config(descr)
|
||||||
|
# assert await cfg.value.get() == {'int': ('forced', ())}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_force_store_value_leadership_sub():
|
async def test_force_store_value_leadership_sub():
|
||||||
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
b = IntOption('int', 'Test int option', multi=True, properties=('force_store_value',))
|
||||||
|
|
|
@ -358,27 +358,6 @@ async def test_meta_new_config_wrong_name():
|
||||||
await delete_sessions(meta)
|
await delete_sessions(meta)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_meta_load_config():
|
|
||||||
od = make_description()
|
|
||||||
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
|
|
||||||
assert len(list(await meta.config.list())) == 2
|
|
||||||
await meta.config.load('name1')
|
|
||||||
assert len(list(await meta.config.list())) == 3
|
|
||||||
await delete_sessions(meta)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_meta_load_config_wrong_name():
|
|
||||||
od = make_description()
|
|
||||||
meta = await MetaConfig(['name1', 'name2'], optiondescription=od)
|
|
||||||
assert len(list(await meta.config.list())) == 2
|
|
||||||
with pytest.raises(ConfigError):
|
|
||||||
await meta.config.load('name3')
|
|
||||||
assert len(list(await meta.config.list())) == 2
|
|
||||||
await delete_sessions(meta)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_meta_meta_set():
|
async def test_meta_meta_set():
|
||||||
meta = await make_metaconfig(double=True)
|
meta = await make_metaconfig(double=True)
|
||||||
|
|
|
@ -1433,14 +1433,11 @@ async def test_calc_value_remove_duplicate(config_type):
|
||||||
async def test_calc_value_join(config_type):
|
async def test_calc_value_join(config_type):
|
||||||
val1 = StrOption('val1', "", 'val1')
|
val1 = StrOption('val1', "", 'val1')
|
||||||
val2 = StrOption('val2', "", 'val2')
|
val2 = StrOption('val2', "", 'val2')
|
||||||
val3 = StrOption('val3', "")
|
val3 = StrOption('val3', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2)), join=ParamValue('.'))))
|
||||||
val4 = StrOption('val4', "", Calculation(calc_value, Params((ParamOption(val1), ParamOption(val2), ParamOption(val3)), join=ParamValue('.'))))
|
od = OptionDescription('root', '', [val1, val2, val3])
|
||||||
od = OptionDescription('root', '', [val1, val2, val3, val4])
|
|
||||||
async with await Config(od) as cfg:
|
async with await Config(od) as cfg:
|
||||||
cfg = await get_config(cfg, config_type)
|
cfg = await get_config(cfg, config_type)
|
||||||
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': None, 'val4': None}
|
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val1.val2'}
|
||||||
await cfg.option('val3').value.set('val3')
|
|
||||||
assert await cfg.value.dict() == {'val1': 'val1', 'val2': 'val2', 'val3': 'val3', 'val4': 'val1.val2.val3'}
|
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import pytest
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
||||||
|
from tiramisu.api import TIRAMISU_VERSION
|
||||||
from tiramisu.setting import groups, owners
|
from tiramisu.setting import groups, owners
|
||||||
from tiramisu import StrOption, IntOption, OptionDescription, submulti, Leadership, Config, \
|
from tiramisu import StrOption, IntOption, OptionDescription, submulti, Leadership, Config, \
|
||||||
MetaConfig, undefined, Params, ParamOption, Calculation
|
MetaConfig, undefined, Params, ParamOption, Calculation
|
||||||
|
@ -37,7 +38,11 @@ async def test_unknown_multi():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_submulti():
|
async def test_submulti():
|
||||||
multi = StrOption('multi', '', multi=submulti)
|
multi = StrOption('multi', '', multi=submulti)
|
||||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
if TIRAMISU_VERSION == 2:
|
||||||
|
default_multi = 'yes'
|
||||||
|
else:
|
||||||
|
default_multi = ['yes']
|
||||||
|
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||||
async with await Config(od) as cfg:
|
async with await Config(od) as cfg:
|
||||||
|
@ -61,7 +66,11 @@ async def test_submulti_default_multi_not_list():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_append_submulti():
|
async def test_append_submulti():
|
||||||
multi = StrOption('multi', '', multi=submulti)
|
multi = StrOption('multi', '', multi=submulti)
|
||||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
if TIRAMISU_VERSION == 2:
|
||||||
|
default_multi = 'yes'
|
||||||
|
else:
|
||||||
|
default_multi = ['yes']
|
||||||
|
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||||
async with await Config(od) as cfg:
|
async with await Config(od) as cfg:
|
||||||
|
@ -95,7 +104,11 @@ async def test_append_submulti():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_append_unvalide_submulti():
|
async def test_append_unvalide_submulti():
|
||||||
multi = StrOption('multi', '', multi=submulti)
|
multi = StrOption('multi', '', multi=submulti)
|
||||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
if TIRAMISU_VERSION == 2:
|
||||||
|
default_multi = 'yes'
|
||||||
|
else:
|
||||||
|
default_multi = ['yes']
|
||||||
|
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||||
async with await Config(od) as cfg:
|
async with await Config(od) as cfg:
|
||||||
|
@ -124,7 +137,11 @@ async def test_append_unvalide_submulti():
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_pop_submulti():
|
async def test_pop_submulti():
|
||||||
multi = StrOption('multi', '', multi=submulti)
|
multi = StrOption('multi', '', multi=submulti)
|
||||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
if TIRAMISU_VERSION == 2:
|
||||||
|
default_multi = 'yes'
|
||||||
|
else:
|
||||||
|
default_multi = ['yes']
|
||||||
|
multi2 = StrOption('multi2', '', default_multi=default_multi, multi=submulti)
|
||||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||||
od = OptionDescription('od', '', [multi, multi2, multi3])
|
od = OptionDescription('od', '', [multi, multi2, multi3])
|
||||||
async with await Config(od) as cfg:
|
async with await Config(od) as cfg:
|
||||||
|
@ -250,27 +267,6 @@ async def test_values_with_leader_and_followers_submulti():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_values_with_leader_and_followers_submulti_default_multi():
|
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
|
||||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=submulti, default_multi=['255.255.0.0', '0.0.0.0'])
|
|
||||||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
|
||||||
maconfig = OptionDescription('toto', '', [interface1])
|
|
||||||
async with await Config(maconfig) as cfg:
|
|
||||||
await cfg.property.read_write()
|
|
||||||
owner = await cfg.owner.get()
|
|
||||||
assert interface1.impl_get_group_type() == groups.leadership
|
|
||||||
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
|
||||||
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
|
||||||
assert await cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
|
||||||
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.0.0', '0.0.0.0']
|
|
||||||
await cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
|
|
||||||
await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
|
||||||
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
|
||||||
assert await cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == ['255.255.0.0', '0.0.0.0']
|
|
||||||
assert not await list_sessions()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_reset_values_with_leader_and_followers_submulti():
|
async def test_reset_values_with_leader_and_followers_submulti():
|
||||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||||
|
@ -433,20 +429,6 @@ async def test_callback_submulti():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
|
||||||
async def test_callback_submulti_follower():
|
|
||||||
multi = StrOption('multi', '', multi=True)
|
|
||||||
multi2 = StrOption('multi2', '', Calculation(return_list), multi=submulti)
|
|
||||||
od = Leadership('multi', '', [multi, multi2])
|
|
||||||
od = OptionDescription('multi', '', [od])
|
|
||||||
async with await Config(od) as cfg:
|
|
||||||
await cfg.property.read_write()
|
|
||||||
assert await cfg.option('multi.multi').value.get() == []
|
|
||||||
await cfg.option('multi.multi').value.set(['val'])
|
|
||||||
assert await cfg.option('multi.multi2', 0).value.get() == ['val', 'val']
|
|
||||||
assert not await list_sessions()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_submulti_unique():
|
async def test_submulti_unique():
|
||||||
i = IntOption('int', '', multi=submulti, properties=('unique',))
|
i = IntOption('int', '', multi=submulti, properties=('unique',))
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
|
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
|
||||||
valid_network_netmask, valid_in_network, valid_broadcast, \
|
valid_network_netmask, valid_in_network, valid_broadcast, \
|
||||||
valid_not_equal
|
valid_not_equal
|
||||||
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
|
from .autolib import Calculation, Params, ParamOption, ParamSelfOption, ParamValue, \
|
||||||
ParamValue, ParamIndex, ParamSuffix
|
ParamIndex, ParamSuffix
|
||||||
from .option import *
|
from .option import *
|
||||||
from .error import APIError
|
from .error import APIError
|
||||||
from .api import Config, MetaConfig, GroupConfig, MixConfig
|
from .api import Config, MetaConfig, GroupConfig, MixConfig
|
||||||
|
@ -31,7 +31,6 @@ from .storage import default_storage, Storage, list_sessions, \
|
||||||
allfuncs = ['Calculation',
|
allfuncs = ['Calculation',
|
||||||
'Params',
|
'Params',
|
||||||
'ParamOption',
|
'ParamOption',
|
||||||
'ParamDynOption',
|
|
||||||
'ParamSelfOption',
|
'ParamSelfOption',
|
||||||
'ParamValue',
|
'ParamValue',
|
||||||
'ParamIndex',
|
'ParamIndex',
|
||||||
|
|
|
@ -52,7 +52,7 @@ class TiramisuHelp:
|
||||||
if module_name in ['forcepermissive', 'unrestraint']:
|
if module_name in ['forcepermissive', 'unrestraint']:
|
||||||
force = True
|
force = True
|
||||||
max_len = max(max_len, len('forcepermissive'))
|
max_len = max(max_len, len('forcepermissive'))
|
||||||
elif module_name != 'help' and not module_name.startswith('_'):
|
elif module_name is not 'help' and not module_name.startswith('_'):
|
||||||
modules.append(module_name)
|
modules.append(module_name)
|
||||||
max_len = max(max_len, len(module_name))
|
max_len = max(max_len, len(module_name))
|
||||||
modules.sort()
|
modules.sort()
|
||||||
|
@ -212,17 +212,6 @@ class _TiramisuOptionOptionDescription(CommonTiramisuOption):
|
||||||
"""Test if option has dependency"""
|
"""Test if option has dependency"""
|
||||||
return self._option_bag.option.impl_has_dependency(self_is_dep)
|
return self._option_bag.option.impl_has_dependency(self_is_dep)
|
||||||
|
|
||||||
@option_and_connection
|
|
||||||
async def dependencies(self):
|
|
||||||
"""Get dependencies from this option"""
|
|
||||||
options = []
|
|
||||||
for option in self._option_bag.option._get_dependencies(self._option_bag.config_bag.context):
|
|
||||||
options.append(TiramisuOption(option().impl_getpath(),
|
|
||||||
None,
|
|
||||||
self._option_bag.config_bag,
|
|
||||||
))
|
|
||||||
return options
|
|
||||||
|
|
||||||
@option_and_connection
|
@option_and_connection
|
||||||
async def isoptiondescription(self):
|
async def isoptiondescription(self):
|
||||||
"""Test if option is an optiondescription"""
|
"""Test if option is an optiondescription"""
|
||||||
|
@ -1544,7 +1533,8 @@ class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextCon
|
||||||
async def new(self,
|
async def new(self,
|
||||||
session_id,
|
session_id,
|
||||||
storage=None,
|
storage=None,
|
||||||
type='config'):
|
type='config',
|
||||||
|
new=None):
|
||||||
"""Create and add a new config"""
|
"""Create and add a new config"""
|
||||||
config = self._config_bag.context
|
config = self._config_bag.context
|
||||||
if storage is None:
|
if storage is None:
|
||||||
|
@ -1555,26 +1545,7 @@ class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextCon
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
storage=storage,
|
storage=storage,
|
||||||
type_=type,
|
type_=type,
|
||||||
)
|
new=new)
|
||||||
return await self._return_config(new_config,
|
|
||||||
storage)
|
|
||||||
|
|
||||||
async def load(self,
|
|
||||||
session_id,
|
|
||||||
storage=None,
|
|
||||||
type='config',
|
|
||||||
):
|
|
||||||
"""Create and add a new config"""
|
|
||||||
config = self._config_bag.context
|
|
||||||
if storage is None:
|
|
||||||
storage = config._storage
|
|
||||||
storage_obj = await storage.get()
|
|
||||||
async with storage_obj.Connection() as connection:
|
|
||||||
new_config = await config.load_config(connection,
|
|
||||||
session_id=session_id,
|
|
||||||
storage=storage,
|
|
||||||
type_=type,
|
|
||||||
)
|
|
||||||
return await self._return_config(new_config,
|
return await self._return_config(new_config,
|
||||||
storage)
|
storage)
|
||||||
|
|
||||||
|
|
|
@ -81,26 +81,6 @@ class ParamOption(Param):
|
||||||
self.raisepropertyerror = raisepropertyerror
|
self.raisepropertyerror = raisepropertyerror
|
||||||
|
|
||||||
|
|
||||||
class ParamDynOption(ParamOption):
|
|
||||||
__slots__ = ('suffix',
|
|
||||||
)
|
|
||||||
def __init__(self,
|
|
||||||
option: 'Option',
|
|
||||||
suffix: str,
|
|
||||||
dynoptiondescription: 'DynOptionDescription',
|
|
||||||
notraisepropertyerror: bool=False,
|
|
||||||
raisepropertyerror: bool=False,
|
|
||||||
todict: bool=False,
|
|
||||||
) -> None:
|
|
||||||
super().__init__(option,
|
|
||||||
notraisepropertyerror,
|
|
||||||
raisepropertyerror,
|
|
||||||
todict,
|
|
||||||
)
|
|
||||||
self.suffix = suffix
|
|
||||||
self.dynoptiondescription = dynoptiondescription
|
|
||||||
|
|
||||||
|
|
||||||
class ParamSelfOption(Param):
|
class ParamSelfOption(Param):
|
||||||
__slots__ = ('todict', 'whole')
|
__slots__ = ('todict', 'whole')
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
@ -156,9 +136,7 @@ class Calculation:
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag,
|
||||||
leadership_must_have_index: bool=False,
|
leadership_must_have_index: bool=False,
|
||||||
orig_value: Any=undefined,
|
orig_value: Any=undefined,
|
||||||
allow_value_error=False,
|
allow_raises=False) -> Any:
|
||||||
force_value_warning=False,
|
|
||||||
) -> Any:
|
|
||||||
return await carry_out_calculation(option_bag.option,
|
return await carry_out_calculation(option_bag.option,
|
||||||
callback=self.function,
|
callback=self.function,
|
||||||
callback_params=self.params,
|
callback_params=self.params,
|
||||||
|
@ -166,9 +144,7 @@ class Calculation:
|
||||||
config_bag=option_bag.config_bag,
|
config_bag=option_bag.config_bag,
|
||||||
leadership_must_have_index=leadership_must_have_index,
|
leadership_must_have_index=leadership_must_have_index,
|
||||||
orig_value=orig_value,
|
orig_value=orig_value,
|
||||||
allow_value_error=allow_value_error,
|
allow_raises=allow_raises)
|
||||||
force_value_warning=force_value_warning,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def help(self,
|
async def help(self,
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag,
|
||||||
|
@ -238,10 +214,7 @@ async def manager_callback(callbk: Union[ParamOption, ParamValue],
|
||||||
value = value[apply_index]
|
value = value[apply_index]
|
||||||
return value
|
return value
|
||||||
|
|
||||||
async def get_value(callbk,
|
async def get_value(callbk, option_bag, path):
|
||||||
option_bag,
|
|
||||||
path,
|
|
||||||
):
|
|
||||||
try:
|
try:
|
||||||
# get value
|
# get value
|
||||||
value = await config_bag.context.getattr(path,
|
value = await config_bag.context.getattr(path,
|
||||||
|
@ -254,10 +227,6 @@ async def manager_callback(callbk: Union[ParamOption, ParamValue],
|
||||||
', {}').format(option.impl_get_display_name(), err), err)
|
', {}').format(option.impl_get_display_name(), err), err)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(option_bag.option.impl_get_display_name(), err))
|
raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(option_bag.option.impl_get_display_name(), err))
|
||||||
except AttributeError as err:
|
|
||||||
raise ConfigError(_('impossible to calculate "{0}", {1}').format(option_bag.option.impl_get_display_name(),
|
|
||||||
err,
|
|
||||||
))
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
async def get_option_bag(config_bag,
|
async def get_option_bag(config_bag,
|
||||||
|
@ -303,25 +272,12 @@ async def manager_callback(callbk: Union[ParamOption, ParamValue],
|
||||||
return {'name': option.impl_get_display_name(),
|
return {'name': option.impl_get_display_name(),
|
||||||
'value': value}
|
'value': value}
|
||||||
|
|
||||||
if isinstance(callbk, ParamOption):
|
# it's ParamOption
|
||||||
callbk_option = callbk.option
|
callbk_option = callbk.option
|
||||||
if callbk_option.issubdyn():
|
if callbk_option.issubdyn():
|
||||||
if isinstance(callbk, ParamDynOption):
|
callbk_option = callbk_option.to_dynoption(option.rootpath,
|
||||||
subdyn = callbk.dynoptiondescription
|
option.impl_getsuffix(),
|
||||||
rootpath = subdyn.impl_getpath() + callbk.suffix
|
callbk_option.getsubdyn())
|
||||||
suffix = callbk.suffix
|
|
||||||
else:
|
|
||||||
if not option.impl_is_dynsymlinkoption():
|
|
||||||
msg = 'option "{}" is not dynamic in callback of the option "{}"'
|
|
||||||
raise ConfigError(_(msg).format(callbk_option.impl_get_display_name(),
|
|
||||||
option.impl_get_display_name(),
|
|
||||||
))
|
|
||||||
rootpath = option.rootpath
|
|
||||||
suffix = option.impl_getsuffix()
|
|
||||||
subdyn = callbk_option.getsubdyn()
|
|
||||||
callbk_option = callbk_option.to_dynoption(rootpath,
|
|
||||||
suffix,
|
|
||||||
subdyn)
|
|
||||||
if leadership_must_have_index and callbk_option.impl_get_leadership() and index is None:
|
if leadership_must_have_index and callbk_option.impl_get_leadership() and index is None:
|
||||||
raise Break()
|
raise Break()
|
||||||
if config_bag is undefined:
|
if config_bag is undefined:
|
||||||
|
@ -344,18 +300,13 @@ async def manager_callback(callbk: Union[ParamOption, ParamValue],
|
||||||
callbk_option,
|
callbk_option,
|
||||||
index_,
|
index_,
|
||||||
False)
|
False)
|
||||||
value = await get_value(callbk,
|
value = await get_value(callbk, option_bag, path)
|
||||||
option_bag,
|
|
||||||
path,
|
|
||||||
)
|
|
||||||
if with_index:
|
if with_index:
|
||||||
value = value[index]
|
value = value[index]
|
||||||
if not callbk.todict:
|
if not callbk.todict:
|
||||||
return value
|
return value
|
||||||
return {'name': callbk_option.impl_get_display_name(),
|
return {'name': callbk_option.impl_get_display_name(),
|
||||||
'value': value}
|
'value': value}
|
||||||
raise ConfigError(_('unknown callback type {} in option {}').format(callbk,
|
|
||||||
option.impl_get_display_name()))
|
|
||||||
|
|
||||||
|
|
||||||
async def carry_out_calculation(option,
|
async def carry_out_calculation(option,
|
||||||
|
@ -365,18 +316,18 @@ async def carry_out_calculation(option,
|
||||||
config_bag: Optional[ConfigBag],
|
config_bag: Optional[ConfigBag],
|
||||||
orig_value=undefined,
|
orig_value=undefined,
|
||||||
leadership_must_have_index: bool=False,
|
leadership_must_have_index: bool=False,
|
||||||
allow_value_error: bool=False,
|
allow_raises: int=False):
|
||||||
force_value_warning: bool=False,
|
|
||||||
):
|
|
||||||
"""a function that carries out a calculation for an option's value
|
"""a function that carries out a calculation for an option's value
|
||||||
|
|
||||||
:param option: the option
|
:param option: the option
|
||||||
:param callback: the name of the callback function
|
:param callback: the name of the callback function
|
||||||
|
:type callback: str
|
||||||
:param callback_params: the callback's parameters
|
:param callback_params: the callback's parameters
|
||||||
(only keyword parameters are allowed)
|
(only keyword parameters are allowed)
|
||||||
|
:type callback_params: dict
|
||||||
:param index: if an option is multi, only calculates the nth value
|
:param index: if an option is multi, only calculates the nth value
|
||||||
:param allow_value_error: to know if carry_out_calculation can return ValueError or ValueWarning (for example if it's a validation)
|
:type index: int
|
||||||
:param force_value_warning: transform valueError to ValueWarning object
|
:param allow_raises: to know if carry_out_calculation is used to validate a value
|
||||||
|
|
||||||
The callback_params is a dict. Key is used to build args (if key is '')
|
The callback_params is a dict. Key is used to build args (if key is '')
|
||||||
and kwargs (otherwise). Values are tuple of:
|
and kwargs (otherwise). Values are tuple of:
|
||||||
|
@ -415,12 +366,11 @@ async def carry_out_calculation(option,
|
||||||
continue
|
continue
|
||||||
ret = calculate(option,
|
ret = calculate(option,
|
||||||
callback,
|
callback,
|
||||||
allow_value_error,
|
allow_raises,
|
||||||
force_value_warning,
|
|
||||||
args,
|
args,
|
||||||
kwargs)
|
kwargs)
|
||||||
if isinstance(ret, list) and not option.impl_is_dynoptiondescription() and \
|
if isinstance(ret, list) and not option.impl_is_dynoptiondescription() and \
|
||||||
option.impl_is_follower() and not option.impl_is_submulti():
|
option.impl_is_follower():
|
||||||
if args or kwargs:
|
if args or kwargs:
|
||||||
raise LeadershipError(_('the "{}" function with positional arguments "{}" '
|
raise LeadershipError(_('the "{}" function with positional arguments "{}" '
|
||||||
'and keyword arguments "{}" must not return '
|
'and keyword arguments "{}" must not return '
|
||||||
|
@ -441,11 +391,9 @@ async def carry_out_calculation(option,
|
||||||
|
|
||||||
def calculate(option,
|
def calculate(option,
|
||||||
callback: Callable,
|
callback: Callable,
|
||||||
allow_value_error: bool,
|
allow_raises: bool,
|
||||||
force_value_warning: bool,
|
|
||||||
args,
|
args,
|
||||||
kwargs,
|
kwargs):
|
||||||
):
|
|
||||||
"""wrapper that launches the 'callback'
|
"""wrapper that launches the 'callback'
|
||||||
|
|
||||||
:param callback: callback function
|
:param callback: callback function
|
||||||
|
@ -455,12 +403,12 @@ def calculate(option,
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return callback(*args, **kwargs)
|
return callback(*args, **kwargs)
|
||||||
except (ValueError, ValueWarning) as err:
|
except ValueError as err:
|
||||||
if allow_value_error:
|
if allow_raises:
|
||||||
if force_value_warning:
|
|
||||||
raise ValueWarning(str(err))
|
|
||||||
raise err
|
raise err
|
||||||
error = err
|
error = err
|
||||||
|
except ValueWarning as err:
|
||||||
|
raise err
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
# import traceback
|
# import traceback
|
||||||
# traceback.print_exc()
|
# traceback.print_exc()
|
||||||
|
|
|
@ -124,18 +124,6 @@ class SubConfig:
|
||||||
await self.reset_one_option_cache(desc,
|
await self.reset_one_option_cache(desc,
|
||||||
resetted_opts,
|
resetted_opts,
|
||||||
doption_bag)
|
doption_bag)
|
||||||
async for coption in self.cfgimpl_get_description().get_children_recursively(None,
|
|
||||||
None,
|
|
||||||
option_bag.config_bag):
|
|
||||||
coption_bag = OptionBag()
|
|
||||||
coption_bag.set_option(coption,
|
|
||||||
option_bag.index,
|
|
||||||
option_bag.config_bag)
|
|
||||||
coption_bag.properties = await self.cfgimpl_get_settings().getproperties(coption_bag)
|
|
||||||
await self.reset_one_option_cache(option,
|
|
||||||
resetted_opts,
|
|
||||||
coption_bag,
|
|
||||||
)
|
|
||||||
elif option.issubdyn():
|
elif option.issubdyn():
|
||||||
# it's an option in dynoptiondescription, remove cache for all generated option
|
# it's an option in dynoptiondescription, remove cache for all generated option
|
||||||
dynopt = option.getsubdyn()
|
dynopt = option.getsubdyn()
|
||||||
|
@ -1188,30 +1176,13 @@ class KernelMixConfig(KernelGroupConfig):
|
||||||
session_id,
|
session_id,
|
||||||
type_='config',
|
type_='config',
|
||||||
storage=None,
|
storage=None,
|
||||||
|
new=None,
|
||||||
):
|
):
|
||||||
if session_id in [child.impl_getname() for child in self._impl_children]:
|
if new is None:
|
||||||
|
new = session_id not in await list_sessions()
|
||||||
|
if new and session_id in [child.impl_getname() for child in self._impl_children]:
|
||||||
raise ConflictError(_('config name must be uniq in '
|
raise ConflictError(_('config name must be uniq in '
|
||||||
'groupconfig for {0}').format(session_id))
|
'groupconfig for {0}').format(session_id))
|
||||||
return await self.load_config(connection,
|
|
||||||
session_id,
|
|
||||||
type_,
|
|
||||||
storage,
|
|
||||||
new=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
async def load_config(self,
|
|
||||||
connection,
|
|
||||||
session_id,
|
|
||||||
type_='config',
|
|
||||||
storage=None,
|
|
||||||
new=False,
|
|
||||||
):
|
|
||||||
if storage is None:
|
|
||||||
storage = self._storage
|
|
||||||
if not new:
|
|
||||||
if session_id not in await list_sessions(storage=storage):
|
|
||||||
raise ConfigError(_('cannot find existing config with session_id to "{}"').format(session_id))
|
|
||||||
|
|
||||||
assert type_ in ('config', 'metaconfig', 'mixconfig'), _('unknown type {}').format(type_)
|
assert type_ in ('config', 'metaconfig', 'mixconfig'), _('unknown type {}').format(type_)
|
||||||
if type_ == 'config':
|
if type_ == 'config':
|
||||||
config = await KernelConfig(self._impl_descr,
|
config = await KernelConfig(self._impl_descr,
|
||||||
|
|
|
@ -311,10 +311,7 @@ class CalcValue:
|
||||||
min_args_len)
|
min_args_len)
|
||||||
if not multi:
|
if not multi:
|
||||||
if join is not None:
|
if join is not None:
|
||||||
if None not in value:
|
|
||||||
value = join.join(value)
|
value = join.join(value)
|
||||||
else:
|
|
||||||
value = None
|
|
||||||
elif value and operator:
|
elif value and operator:
|
||||||
new_value = value[0]
|
new_value = value[0]
|
||||||
op = {'mul': mul,
|
op = {'mul': mul,
|
||||||
|
|
|
@ -55,8 +55,7 @@ def get_translation() -> str:
|
||||||
trans = translation(domain=app_name,
|
trans = translation(domain=app_name,
|
||||||
localedir=translations_path,
|
localedir=translations_path,
|
||||||
languages=[user_locale],
|
languages=[user_locale],
|
||||||
)
|
codeset='UTF-8')
|
||||||
# codeset='UTF-8')
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
log.debug('cannot found translation file for langage {} in localedir {}'.format(user_locale,
|
log.debug('cannot found translation file for langage {} in localedir {}'.format(user_locale,
|
||||||
translations_path))
|
translations_path))
|
||||||
|
|
|
@ -106,7 +106,7 @@ class Base:
|
||||||
context_od) -> Set[str]:
|
context_od) -> Set[str]:
|
||||||
ret = set(getattr(self, '_dependencies', STATIC_TUPLE))
|
ret = set(getattr(self, '_dependencies', STATIC_TUPLE))
|
||||||
if context_od and hasattr(context_od, '_dependencies'):
|
if context_od and hasattr(context_od, '_dependencies'):
|
||||||
# add options that have context is set in calculation
|
# if context is set in options, add those options
|
||||||
return set(context_od._dependencies) | ret
|
return set(context_od._dependencies) | ret
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -270,36 +270,20 @@ class BaseOption(Base):
|
||||||
return self.impl_get_callback()[0] is not None
|
return self.impl_get_callback()[0] is not None
|
||||||
|
|
||||||
def _impl_get_display_name(self,
|
def _impl_get_display_name(self,
|
||||||
dyn_name: Base=None,
|
dyn_name: Base=None) -> str:
|
||||||
suffix: str=None,
|
|
||||||
) -> str:
|
|
||||||
name = self.impl_get_information('doc', None)
|
name = self.impl_get_information('doc', None)
|
||||||
if name is None or name == '':
|
if name is None or name == '':
|
||||||
if dyn_name is not None:
|
if dyn_name is not None:
|
||||||
name = dyn_name
|
name = dyn_name
|
||||||
else:
|
else:
|
||||||
name = self.impl_getname()
|
name = self.impl_getname()
|
||||||
elif suffix:
|
|
||||||
name += suffix
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def _get_display_name(self,
|
def impl_get_display_name(self,
|
||||||
dyn_name,
|
dyn_name: Base=None) -> str:
|
||||||
suffix,
|
|
||||||
):
|
|
||||||
if hasattr(self, '_display_name_function'):
|
if hasattr(self, '_display_name_function'):
|
||||||
return self._display_name_function(self,
|
return self._display_name_function(self, dyn_name)
|
||||||
dyn_name,
|
return self._impl_get_display_name(dyn_name)
|
||||||
suffix,
|
|
||||||
)
|
|
||||||
return self._impl_get_display_name(dyn_name,
|
|
||||||
suffix,
|
|
||||||
)
|
|
||||||
|
|
||||||
def impl_get_display_name(self) -> str:
|
|
||||||
return self._get_display_name(None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
|
|
||||||
def reset_cache(self,
|
def reset_cache(self,
|
||||||
path: str,
|
path: str,
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
import re
|
import re
|
||||||
from typing import List, Callable
|
from typing import List, Callable
|
||||||
from itertools import chain
|
|
||||||
from ..autolib import ParamOption
|
|
||||||
|
|
||||||
|
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
|
@ -62,11 +60,7 @@ class DynOptionDescription(OptionDescription):
|
||||||
'dynoptiondescription'))
|
'dynoptiondescription'))
|
||||||
child._setsubdyn(self)
|
child._setsubdyn(self)
|
||||||
# add suffixes
|
# add suffixes
|
||||||
if __debug__ and not isinstance(suffixes, Calculation):
|
if __debug__ and isinstance(suffixes, Calculation):
|
||||||
raise ConfigError(_('suffixes in dynoptiondescription has to be a calculation'))
|
|
||||||
for param in chain(suffixes.params.args, suffixes.params.kwargs.values()):
|
|
||||||
if isinstance(param, ParamOption):
|
|
||||||
param.option._add_dependency(self)
|
|
||||||
self._suffixes = suffixes
|
self._suffixes = suffixes
|
||||||
|
|
||||||
def convert_suffix_to_path(self,
|
def convert_suffix_to_path(self,
|
||||||
|
|
|
@ -62,9 +62,7 @@ class IPOption(StrOption):
|
||||||
|
|
||||||
def _validate_ip(self, value):
|
def _validate_ip(self, value):
|
||||||
try:
|
try:
|
||||||
new_value = str(ip_address(value))
|
ip_address(value)
|
||||||
if value != new_value:
|
|
||||||
raise ValueError(f'should be {new_value}')
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,7 @@ class Option(BaseOption):
|
||||||
is_multi = True
|
is_multi = True
|
||||||
_multi = submulti
|
_multi = submulti
|
||||||
else:
|
else:
|
||||||
raise ValueError(_('invalid multi type "{}" for "{}"').format(multi,
|
raise ValueError(_('invalid multi type "{}"').format(multi))
|
||||||
name,
|
|
||||||
))
|
|
||||||
if _multi != 1:
|
if _multi != 1:
|
||||||
_setattr(self, '_multi', _multi)
|
_setattr(self, '_multi', _multi)
|
||||||
if multi is not False and default is None:
|
if multi is not False and default is None:
|
||||||
|
@ -95,11 +93,12 @@ class Option(BaseOption):
|
||||||
doc,
|
doc,
|
||||||
properties=properties,
|
properties=properties,
|
||||||
is_multi=is_multi)
|
is_multi=is_multi)
|
||||||
|
if __debug__:
|
||||||
if validators is not None:
|
if validators is not None:
|
||||||
if __debug__ and not isinstance(validators, list):
|
if not isinstance(validators, list):
|
||||||
raise ValueError(_('validators must be a list of Calculation for "{}"').format(name))
|
raise ValueError(_('validators must be a list of Calculation for "{}"').format(name))
|
||||||
for validator in validators:
|
for validator in validators:
|
||||||
if __debug__ and not isinstance(validator, Calculation):
|
if not isinstance(validator, Calculation):
|
||||||
raise ValueError(_('validators must be a Calculation for "{}"').format(name))
|
raise ValueError(_('validators must be a Calculation for "{}"').format(name))
|
||||||
for param in chain(validator.params.args, validator.params.kwargs.values()):
|
for param in chain(validator.params.args, validator.params.kwargs.values()):
|
||||||
if isinstance(param, ParamOption):
|
if isinstance(param, ParamOption):
|
||||||
|
@ -337,9 +336,7 @@ class Option(BaseOption):
|
||||||
if ((check_error and not calc_is_warnings_only) or
|
if ((check_error and not calc_is_warnings_only) or
|
||||||
(not check_error and calc_is_warnings_only)):
|
(not check_error and calc_is_warnings_only)):
|
||||||
try:
|
try:
|
||||||
kwargs = {'allow_value_error': True,
|
kwargs = {'allow_raises': True}
|
||||||
'force_value_warning': calc_is_warnings_only,
|
|
||||||
}
|
|
||||||
if _index is not None and option_bag.index == _index:
|
if _index is not None and option_bag.index == _index:
|
||||||
soption_bag = option_bag
|
soption_bag = option_bag
|
||||||
else:
|
else:
|
||||||
|
@ -350,6 +347,17 @@ class Option(BaseOption):
|
||||||
await validator.execute(soption_bag,
|
await validator.execute(soption_bag,
|
||||||
leadership_must_have_index=True,
|
leadership_must_have_index=True,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
except ValueError as err:
|
||||||
|
if calc_is_warnings_only:
|
||||||
|
warnings.warn_explicit(ValueWarning(val,
|
||||||
|
self._display_name,
|
||||||
|
self,
|
||||||
|
'{0}'.format(err),
|
||||||
|
_index),
|
||||||
|
ValueWarning,
|
||||||
|
self.__class__.__name__, 306)
|
||||||
|
else:
|
||||||
|
raise err
|
||||||
except ValueWarning as warn:
|
except ValueWarning as warn:
|
||||||
warnings.warn_explicit(ValueWarning(val,
|
warnings.warn_explicit(ValueWarning(val,
|
||||||
self._display_name,
|
self._display_name,
|
||||||
|
@ -357,7 +365,7 @@ class Option(BaseOption):
|
||||||
'{0}'.format(warn),
|
'{0}'.format(warn),
|
||||||
_index),
|
_index),
|
||||||
ValueWarning,
|
ValueWarning,
|
||||||
self.__class__.__name__, 356)
|
self.__class__.__name__, 316)
|
||||||
|
|
||||||
async def do_validation(_value,
|
async def do_validation(_value,
|
||||||
_index):
|
_index):
|
||||||
|
|
|
@ -59,9 +59,7 @@ class SynDynOption:
|
||||||
return self.opt.impl_getname() + self.suffix
|
return self.opt.impl_getname() + self.suffix
|
||||||
|
|
||||||
def impl_get_display_name(self) -> str:
|
def impl_get_display_name(self) -> str:
|
||||||
return self.opt._get_display_name(dyn_name=self.impl_getname(),
|
return self.opt.impl_get_display_name(dyn_name=self.impl_getname()) + self.suffix
|
||||||
suffix=self.suffix,
|
|
||||||
)
|
|
||||||
|
|
||||||
def impl_getsuffix(self) -> str:
|
def impl_getsuffix(self) -> str:
|
||||||
return self.suffix
|
return self.suffix
|
||||||
|
|
|
@ -198,19 +198,7 @@ class Values:
|
||||||
# now try to get default value:
|
# now try to get default value:
|
||||||
value = await self.calc_value(option_bag,
|
value = await self.calc_value(option_bag,
|
||||||
option_bag.option.impl_getdefault())
|
option_bag.option.impl_getdefault())
|
||||||
if option_bag.index is not None and isinstance(value, (list, tuple)):
|
if option_bag.option.impl_is_multi() and option_bag.index is not None and isinstance(value, (list, tuple)):
|
||||||
if value and option_bag.option.impl_is_submulti():
|
|
||||||
# first index is a list, assume other data are list too
|
|
||||||
if isinstance(value[0], list):
|
|
||||||
# if index, must return good value for this index
|
|
||||||
if len(value) > option_bag.index:
|
|
||||||
value = value[option_bag.index]
|
|
||||||
else:
|
|
||||||
# no value for this index, retrieve default multi value
|
|
||||||
# default_multi is already a list for submulti
|
|
||||||
value = await self.calc_value(option_bag,
|
|
||||||
option_bag.option.impl_getdefault_multi())
|
|
||||||
elif option_bag.option.impl_is_multi():
|
|
||||||
# if index, must return good value for this index
|
# if index, must return good value for this index
|
||||||
if len(value) > option_bag.index:
|
if len(value) > option_bag.index:
|
||||||
value = value[option_bag.index]
|
value = value[option_bag.index]
|
||||||
|
@ -241,8 +229,7 @@ class Values:
|
||||||
await option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
|
await option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
|
||||||
|
|
||||||
async def calculate_value(self,
|
async def calculate_value(self,
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag) -> Any:
|
||||||
) -> Any:
|
|
||||||
|
|
||||||
# if value has callback, calculate value
|
# if value has callback, calculate value
|
||||||
callback, callback_params = option_bag.option.impl_get_callback()
|
callback, callback_params = option_bag.option.impl_get_callback()
|
||||||
|
|
Loading…
Reference in New Issue