remove _cache_paths (path is now directly in option)

better TiramisuAPI support
This commit is contained in:
Emmanuel Garette 2018-09-08 20:17:20 +02:00
parent e0cab0063e
commit aa9aef6e78
13 changed files with 627 additions and 633 deletions

File diff suppressed because it is too large Load diff

View file

@ -47,8 +47,8 @@ def test_cache_config():
def test_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings()
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
@ -98,8 +98,8 @@ def test_cache_importation_permissive():
def test_cache_reset():
od1 = make_description()
cfg = Config(od1)
values = cfg._config.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings()
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
#when change a value
cfg.option('u1').value.get()
cfg.option('u2').value.get()
@ -158,8 +158,8 @@ def test_cache_reset():
def test_cache_reset_multi():
od1 = make_description()
cfg = Config(od1)
values = cfg._config.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings()
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get()
cfg.option('u3').value.get()
assert 'u1' in values._p_.get_cached()
@ -210,12 +210,12 @@ def test_cache_reset_multi():
def test_reset_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings()
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.option('u1').value.get()
assert 'u1' in values._p_.get_cached()
assert 'u1' in settings._p_.get_cached()
cfg._config.cfgimpl_reset_cache(None, None)
cfg._config_bag.context.cfgimpl_reset_cache(None, None)
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
cfg.option('u1').value.get()
@ -227,7 +227,7 @@ def test_reset_cache():
assert 'u1' in settings._p_.get_cached()
assert 'u2' in values._p_.get_cached()
assert 'u2' in settings._p_.get_cached()
cfg._config.cfgimpl_reset_cache(None, None)
cfg._config_bag.context.cfgimpl_reset_cache(None, None)
assert 'u1' not in values._p_.get_cached()
assert 'u1' not in settings._p_.get_cached()
assert 'u2' not in values._p_.get_cached()
@ -237,8 +237,8 @@ def test_reset_cache():
def test_cache_not_cache():
od1 = make_description()
cfg = Config(od1)
values = cfg._config.cfgimpl_get_values()
settings = cfg._config.cfgimpl_get_settings()
values = cfg._config_bag.context.cfgimpl_get_values()
settings = cfg._config_bag.context.cfgimpl_get_settings()
cfg.property.pop('cache')
cfg.option('u1').value.get()
assert 'u1' not in values._p_.get_cached()
@ -253,13 +253,13 @@ def test_cache_master_slave():
maconfig = OptionDescription('toto', '', [interface1])
cfg = Config(maconfig)
cfg.property.read_write()
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
#
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2'])
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cache = cfg._config.cfgimpl_get_values()._p_.get_cached()
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
if TIRAMISU_VERSION == 2:
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
else:
@ -269,7 +269,7 @@ def test_cache_master_slave():
#assert set(cache['ip_admin_eth0.netmask_admin_eth0'].keys()) == set([None])
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
cache = cfg._config.cfgimpl_get_settings()._p_.get_cached()
cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached()
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
@ -282,7 +282,7 @@ def test_cache_master_slave():
cfg.option('ip_admin_eth0.ip_admin_eth0').value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
cache = cfg._config.cfgimpl_get_values()._p_.get_cached()
cache = cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached()
if TIRAMISU_VERSION == 2:
assert set(cache.keys()) == set(['ip_admin_eth0.ip_admin_eth0'])
else:
@ -293,7 +293,7 @@ def test_cache_master_slave():
#assert cache['ip_admin_eth0.netmask_admin_eth0'][None][0] == [None, None]
#assert cache['ip_admin_eth0.netmask_admin_eth0'][0][0] is None
#assert cache['ip_admin_eth0.netmask_admin_eth0'][1][0] is None
cache = cfg._config.cfgimpl_get_settings()._p_.get_cached()
cache = cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached()
assert set(cache.keys()) == set([None, 'ip_admin_eth0', 'ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
assert set(cache['ip_admin_eth0'].keys()) == set([None])
assert set(cache['ip_admin_eth0.ip_admin_eth0'].keys()) == set([None])
@ -329,79 +329,79 @@ def test_cache_callback():
if TIRAMISU_VERSION == 2:
cfg.property.pop('expire')
cfg.config.dict()
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('val', None)},
'val2': {None: ('val', None)},
'val3': {None: ('yes', None)},
'val4': {None: ('val', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val1').value.set('new')
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val3': {None: ('yes', None)},
'val5': {None: (['yes'], None)}})
cfg.config.dict()
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('yes', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val3').value.set('new2')
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
cfg.config.dict()
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val4').value.set('new3')
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val5': {None: (['yes'], None)}})
cfg.config.dict()
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
'val5': {None: (['yes'], None)}})
cfg.option('val5').value.set([undefined, 'new4'])
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)},
# 'val5': {None: (set(['empty']), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)}})
cfg.config.dict()
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)},
# 'val3': {None: (set([]), None)},
# 'val4': {None: (set([]), None)},
# 'val5': {None: (set(['empty']), None)}}
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1': {None: ('new', None)},
'val2': {None: ('new', None)},
'val3': {None: ('new2', None)},
'val4': {None: ('new3', None)},
@ -435,19 +435,19 @@ def test_cache_master_and_slaves_master():
#None because no value
idx_val2 = None
if TIRAMISU_VERSION == 2:
assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
else:
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {idx_val2: (val1_val2_props, None)}})
# len is 0 so don't get any value
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
#
cfg.option('val1.val1').value.set([undefined])
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.config.dict()
if TIRAMISU_VERSION == 2:
val_val2 = [None]
@ -457,30 +457,30 @@ def test_cache_master_and_slaves_master():
idx_val2 = 0
val_val2 = None
val_val2_props = {idx_val2: (val1_val2_props, None), None: (set(), None)}
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': val_val2_props})
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([None], None)},
'val1.val2': {idx_val2: (val_val2, None)}})
cfg.option('val1.val1').value.set([undefined, undefined])
cfg.config.dict()
cfg.option('val1.val2', 1).value.set('oui')
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
if TIRAMISU_VERSION == 2:
val1_val2_props = {None: (set([]), None), 0: (set([]), None), 1: (set([]), None)}
else:
val1_val2_props = {0: (frozenset([]), None), 1: (frozenset([]), None)}
#assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
#assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (global_props, None)},
# 'val1': {None: (val1_props, None)},
# 'val1.val1': {None: (val1_val1_props, None)},
# 'val1.val2': val1_val2_props}
#if TIRAMISU_VERSION == 2:
# assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
# assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
# 'val1.val2': {None: ([None, 'oui'], None)}}
#else:
# assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
# assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None, None], None)},
# 'val1.val2': {0: (None, None), 1: ('oui', None)}}
@ -509,22 +509,22 @@ def test_cache_master_callback():
val1_val1_props = frozenset(val1_val1_props)
val1_val2_props = frozenset(val1_val2_props)
if TIRAMISU_VERSION == 2:
assert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
else:
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (global_props, None)},
'val1': {None: (val1_props, None)},
'val1.val1': {None: (val1_val1_props, None)},
'val1.val2': {None: (val1_val2_props, None)}})
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'val1.val1': {None: ([], None)}})
cfg.option('val1.val1').value.set([undefined])
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.config.dict()
#FIXMEassert cfg._config.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
#FIXMEassert cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached() == {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
# 'val1': {None: (set([]), None)}}
#FIXMEassert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
#FIXMEassert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'val1.val1': {None: ([None], None)},
# 'val1.val2': {None: ([None], None)}
# }
@ -538,46 +538,46 @@ def test_cache_requires():
cfg.property.read_write()
if TIRAMISU_VERSION == 2:
cfg.property.pop('expire')
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
if TIRAMISU_VERSION == 2:
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
else:
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
cfg.config.dict()
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
cfg.option('ip_address_service').value.set('1.1.1.1')
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)}})
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (True, None)}})
cfg.config.dict()
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: ('1.1.1.1', None)},
'activate_service': {None: (True, None)}})
cfg.option('activate_service').value.set(False)
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)}})
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
cfg.config.dict()
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set(['disabled']), None)}})
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}})
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'activate_service': {None: (False, None)}})
def test_cache_global_properties():
@ -587,25 +587,25 @@ def test_cache_global_properties():
od = OptionDescription('service', '', [a, b])
cfg = Config(od)
cfg.property.read_write()
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {}
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'disabled', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
if TIRAMISU_VERSION == 2:
assert cfg._config.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
assert cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached() == {'ip_address_service': {None: (None, None)}}
else:
compare(cfg._config.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
compare(cfg._config_bag.context.cfgimpl_get_values()._p_.get_cached(), {'ip_address_service': {None: (None, None)},
'activate_service': {None: (True, None)}})
cfg.property.pop('disabled')
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})
cfg.property.add('test')
assert cfg.option('ip_address_service').value.get() == None
compare(cfg._config.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)},
compare(cfg._config_bag.context.cfgimpl_get_settings()._p_.get_cached(), {None: {None: (set(['cache', 'frozen', 'hidden', 'validator', 'warnings', 'test']), None)},
'activate_service': {None: (set([]), None)},
'ip_address_service': {None: (set([]), None)}})

View file

@ -145,17 +145,6 @@ def test_information_config():
raises(ValueError, "config.information.reset('noinfo')")
def test_config_impl_get_path_by_opt():
descr = make_description()
config = Config(descr)
dummy = config.option('gc.dummy').option.get()
boo = config.option('bool').option.get()
unknown = IntOption('test', '')
unknown
assert config._config.cfgimpl_get_description().impl_get_path_by_opt(boo) == 'bool'
assert config._config.cfgimpl_get_description().impl_get_path_by_opt(dummy) == 'gc.dummy'
def to_tuple(val):
ret = []
for v in val:

View file

@ -19,7 +19,7 @@ def test_deref_storage():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c._config.cfgimpl_get_values()._p_)
w = weakref.ref(c._config_bag.context.cfgimpl_get_values()._p_)
del(c)
assert w() is None
@ -28,7 +28,7 @@ def test_deref_value():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c._config.cfgimpl_get_values())
w = weakref.ref(c._config_bag.context.cfgimpl_get_values())
del(c)
assert w() is None
@ -37,7 +37,7 @@ def test_deref_setting():
b = BoolOption('b', '')
o = OptionDescription('od', '', [b])
c = Config(o)
w = weakref.ref(c._config.cfgimpl_get_settings())
w = weakref.ref(c._config_bag.context.cfgimpl_get_settings())
del(c)
assert w() is None

View file

@ -199,26 +199,26 @@ def test_meta_meta_set():
errors2 = meta.value.set('od1.i6', 7, only_config=True)
assert len(errors1) == 0
assert len(errors2) == 2
conf1 = meta.config('meta.conf1')._config
conf2 = meta.config('meta.conf2')._config
conf1 = meta.config('meta.conf1')._config_bag.context
conf2 = meta.config('meta.conf2')._config_bag.context
assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7
#
dconfigs = []
for conf in meta.config.find('i1', value=7, first=True).config.list():
dconfigs.append(conf._config)
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
meta.config('meta.conf1').option('od1.i1').value.set(8)
#
dconfigs = []
for conf in meta.config.find('i1', first=True).config.list():
dconfigs.append(conf._config)
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config
assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config
assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config_bag.context
assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config_bag.context
#
dconfigs = []
for conf in meta.config.find('i5', value=2, first=True).config.list():
dconfigs.append(conf._config)
dconfigs.append(conf._config_bag.context)
assert [conf1, conf2] == dconfigs
#
raises(AttributeError, "meta.config.find('i1', value=10, first=True)")
@ -258,8 +258,8 @@ def test_group_find_firsts():
conf2 = Config(od2, session_id='conf2')
grp = GroupConfig([conf1, conf2])
itr = grp.config.find('i1', first=True).config.list()
conf1._config == next(itr)._config
conf2._config == next(itr)._config
conf1._config_bag.context == next(itr)._config_bag.context
conf2._config_bag.context == next(itr)._config_bag.context
def test_group_group():
@ -307,20 +307,20 @@ def test_meta_master_slaves():
meta = MetaConfig([conf1, conf2])
meta.property.read_only()
itr = meta.config.find('ip_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config
assert conf2._config == next(itr)._config
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config
assert conf2._config == next(itr)._config
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
meta.property.read_write()
raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)")
itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config
assert conf2._config == next(itr)._config
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
meta.property.read_only()
itr = meta.config.find('netmask_admin_eth0', first=True).config.list()
assert conf1._config == next(itr)._config
assert conf2._config == next(itr)._config
assert conf1._config_bag.context == next(itr)._config_bag.context
assert conf2._config_bag.context == next(itr)._config_bag.context
def test_meta_master_slaves_value2():

View file

@ -79,6 +79,7 @@ def test_permissive_frozen():
api.property.read_write()
api.unrestraint.permissive.set(frozenset(['frozen', 'disabled']))
assert api.unrestraint.permissive.get() == frozenset(['frozen', 'disabled'])
assert api.permissive.get() == frozenset(['frozen', 'disabled'])
try:
api.option('u1').value.set(1)
except PropertiesOptionError as err:

View file

@ -150,14 +150,14 @@ def test_slots_config():
od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1])
c = Config(od2)
raises(AttributeError, "c._config.x = 1")
raises(AttributeError, "c._config.cfgimpl_x = 1")
raises(AttributeError, "c._config_bag.context.x = 1")
raises(AttributeError, "c._config_bag.context.cfgimpl_x = 1")
option_bag = OptionBag()
option_bag.set_option(od2,
'a',
None,
ConfigBag(c._config))
sc = c._config.get_subconfig('a', option_bag)
ConfigBag(c._config_bag.context))
sc = c._config_bag.context.get_subconfig('a', option_bag)
assert isinstance(sc, SubConfig)
raises(AttributeError, "sc.x = 1")
raises(AttributeError, "sc.cfgimpl_x = 1")
@ -167,7 +167,7 @@ def test_slots_setting():
od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1])
c = Config(od2)
s = c._config.cfgimpl_get_settings()
s = c._config_bag.context.cfgimpl_get_settings()
s
raises(AttributeError, "s.x = 1")
@ -176,6 +176,6 @@ def test_slots_value():
od1 = OptionDescription('a', '', [])
od2 = OptionDescription('a', '', [od1])
c = Config(od2)
v = c._config.cfgimpl_get_values()
v = c._config_bag.context.cfgimpl_get_values()
v
raises(AttributeError, "v.x = 1")

View file

@ -223,7 +223,7 @@ def test_diff_information_config():
b.impl_set_information('info2', 'oh')
o = OptionDescription('o', '', [b])
o1 = OptionDescription('o1', '', [o])
c = Config(o1)._config
c = Config(o1)._config_bag.context
raises(NotImplementedError, "dumps(c)")

View file

@ -113,7 +113,7 @@ class CommonTiramisu(TiramisuHelp):
if option is None:
option = self.subconfig.cfgimpl_get_description().impl_getchild(self._name,
self.option_bag.config_bag,
self.subconfig)
self.subconfig.cfgimpl_get_path())
self.option_bag.set_option(option,
self.option_bag.path,
self.option_bag.index,
@ -145,8 +145,8 @@ class CommonTiramisuOption(CommonTiramisu):
self.option_bag = option_bag
self._name = name
self.subconfig = subconfig
# for help()
if option_bag is not None:
# for help()
self._get_option()
if option_bag.config_bag is not None and self.slave_need_index:
self._test_slave_index()
@ -548,11 +548,21 @@ class TiramisuOption(CommonTiramisu):
"""find an option by name (only for optiondescription)"""
if not first:
ret = []
for path in self.config_bag.context.find(byname=name,
byvalue=value,
bytype=type,
_subpath=self._path,
config_bag=self.config_bag):
option = self._get_option()
oname = option.impl_getname()
path = self.subconfig._get_subpath(oname)
option_bag = OptionBag()
option_bag.set_option(option,
path,
None,
self.config_bag)
subconfig = self.subconfig.get_subconfig(oname,
option_bag)
for path in subconfig.find(byname=name,
byvalue=value,
bytype=type,
_subpath=self._path,
config_bag=self.config_bag):
subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag)
t_option = TiramisuOption(name,
@ -569,7 +579,7 @@ class TiramisuOption(CommonTiramisu):
self._get_option()
current_option = self.option_bag.option.impl_getchild(name,
self.config_bag,
self.subconfig)
self.subconfig.cfgimpl_get_path)
path = self.option_bag.path + '.' + name
option_bag= OptionBag()
option_bag.set_option(current_option,
@ -614,8 +624,8 @@ class TiramisuOption(CommonTiramisu):
self.subconfig.get_subconfig(name,
option_bag)
else:
self.subconfig.getattr(name,
option_bag)
subconfig.getattr(name,
option_bag)
option = self._get_option()
name = option.impl_getname()
@ -738,10 +748,7 @@ class TiramisuContextProperty(TiramisuContext):
"""set configuration to read only mode"""
settings = self.config_bag.context.cfgimpl_get_settings()
settings.read_only(self.config_bag.context)
try:
del self.config_bag.properties
except AttributeError:
pass
del self.config_bag.properties
def read_write(self):
"""set configuration to read and write mode"""
@ -750,17 +757,15 @@ class TiramisuContextProperty(TiramisuContext):
# #FIXME ?
permissives = frozenset(settings.get_context_permissives() | frozenset(['hidden']))
settings.set_context_permissives(permissives)
try:
del self.config_bag.properties
except AttributeError:
pass
#/FIXME ?
del self.config_bag.properties
def add(self, prop):
"""add a configuration property"""
props = self.get()
props.add(prop)
self.set(frozenset(props))
del self.config_bag.properties
def pop(self, prop):
"""remove a configuration property"""
@ -768,6 +773,7 @@ class TiramisuContextProperty(TiramisuContext):
if prop in props:
props.remove(prop)
self.set(frozenset(props))
del self.config_bag.properties
def get(self):
"""get all configuration properties"""
@ -778,12 +784,14 @@ class TiramisuContextProperty(TiramisuContext):
context = self.config_bag.context
context.cfgimpl_get_settings().set_context_properties(props,
context)
del self.config_bag.properties
def reset(self):
"""remove configuration properties"""
context = self.config_bag.context
context.cfgimpl_get_settings().reset(None,
context)
del self.config_bag.properties
def exportation(self):
"""export configuration properties"""
@ -794,6 +802,7 @@ class TiramisuContextProperty(TiramisuContext):
self.config_bag.context.cfgimpl_get_settings()._p_.importation(properties)
self.config_bag.context.cfgimpl_reset_cache(None,
None)
del self.config_bag.properties
class TiramisuContextPermissive(TiramisuContext):
@ -806,6 +815,7 @@ class TiramisuContextPermissive(TiramisuContext):
def set(self, permissives):
"""set configuration permissives"""
self.config_bag.context.cfgimpl_get_settings().set_context_permissives(permissives)
del self.config_bag.permissives
def exportation(self):
"""export configuration permissives"""
@ -816,6 +826,7 @@ class TiramisuContextPermissive(TiramisuContext):
self.config_bag.context.cfgimpl_get_settings()._pp_.importation(permissives)
self.config_bag.context.cfgimpl_reset_cache(None,
None)
del self.config_bag.permissives
@ -918,9 +929,9 @@ class TiramisuContextConfig(TiramisuContext):
first: bool=False):
"""find a path from option name and optionnaly a value to MetaConfig or GroupConfig"""
if first:
return TiramisuAPI(self.config_bag.context.find_firsts(byname=name,
byvalue=value,
config_bag=self.config_bag))
return Config(self.config_bag.context.find_firsts(byname=name,
byvalue=value,
config_bag=self.config_bag))
else:
raise APIError('not implemented yet')
@ -929,25 +940,25 @@ class TiramisuContextConfig(TiramisuContext):
def _c_copy(self,
session_id=None):
return TiramisuAPI(self.config_bag.context.duplicate(session_id))
return Config(self.config_bag.context.duplicate(session_id))
def _c_deepcopy(self,
session_id=None):
return TiramisuAPI(self.config_bag.context.duplicate(session_id,
deep=True))
return Config(self.config_bag.context.duplicate(session_id,
deep=True))
def _c_meta(self):
return TiramisuAPI(self.config_bag.context.cfgimpl_get_meta())
return Config(self.config_bag.context.cfgimpl_get_meta())
def _m_new(self, name):
return TiramisuAPI(self.config_bag.context.new_config(name))
return Config(self.config_bag.context.new_config(name))
def _m_list(self):
return self._g_list()
def _g_list(self):
for child in self.config_bag.context.cfgimpl_get_children():
yield TiramisuAPI(child)
yield Config(child)
def __getattr__(self,
name: str) -> Callable:
@ -990,32 +1001,25 @@ class TiramisuAPI(TiramisuHelp):
def __init__(self,
config) -> None:
self._config = config
if not isinstance(config, ConfigBag):
config = ConfigBag(context=config)
self._config_bag = config
if not self.registers:
registers(self.registers, 'TiramisuContext')
registers(self.registers, 'TiramisuDispatcher')
def __getattr__(self, subfunc: str) -> Any:
if subfunc == 'forcepermissive':
if isinstance(self._config, ConfigBag):
config_bag = self._config.copy()
del config_bag.properties
else:
config_bag = ConfigBag(context=self._config)
config_bag = self._config_bag.copy()
config_bag.set_permissive()
return TiramisuAPI(config_bag)
elif subfunc == 'unrestraint':
if isinstance(self._config, ConfigBag):
config_bag = self._config.copy()
else:
config_bag = ConfigBag(context=self._config)
config_bag = self._config_bag.copy()
config_bag.properties = frozenset()
return TiramisuAPI(config_bag)
elif subfunc in self.registers:
if not isinstance(self._config, ConfigBag):
config_bag = ConfigBag(context=self._config)
else:
config_bag = self._config
config_bag = self._config_bag
del config_bag.permissives
return self.registers[subfunc](config_bag)
else:
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
@ -1055,7 +1059,7 @@ class Config(TiramisuAPI):
session_id: str=None,
persistent: bool=False,
storage=None) -> None:
if not isinstance(descr, (KernelConfig, KernelMetaConfig)):
if isinstance(descr, OptionDescription):
config = KernelConfig(descr,
session_id=session_id,
persistent=persistent,
@ -1075,7 +1079,7 @@ class MetaConfig(TiramisuAPI):
_children = []
for child in children:
if isinstance(child, TiramisuAPI):
_children.append(child._config)
_children.append(child._config_bag.context)
else:
_children.append(child)
@ -1095,7 +1099,7 @@ class GroupConfig(TiramisuAPI):
storage=None) -> None:
_children = []
for child in children:
_children.append(child._config)
_children.append(child._config_bag.context)
config = KernelGroupConfig(_children,
session_id=session_id,

View file

@ -199,7 +199,7 @@ class SubConfig(object):
option_bag = OptionBag()
option = self.cfgimpl_get_description().impl_getchild(step,
config_bag,
self)
self.cfgimpl_get_path())
subpath = self._get_subpath(step)
option_bag.set_option(option,
subpath,
@ -371,7 +371,7 @@ class SubConfig(object):
"""
def _filter_by_value(soption_bag):
try:
value = self.getattr(path,
value = context.getattr(path,
soption_bag)
except PropertiesOptionError:
return False
@ -386,8 +386,10 @@ class SubConfig(object):
else:
options = self.cfgimpl_get_description().impl_get_options_paths(bytype,
byname,
_subpath,
self.cfgimpl_get_path(),
config_bag)
options = list(options)
context = self.cfgimpl_get_context()
for path, option in options:
option_bag = OptionBag()
option_bag.set_option(option,
@ -400,14 +402,14 @@ class SubConfig(object):
#remove option with propertyerror, ...
try:
if '.' in path:
subconfig, subpath = self.cfgimpl_get_home_by_path(path,
subconfig, subpath = context.cfgimpl_get_home_by_path(path,
config_bag)
else:
subconfig = self
subpath = path
subconfig.cfgimpl_get_description().impl_getchild(subpath,
config_bag,
subconfig)
subconfig.cfgimpl_get_path())
self.cfgimpl_get_settings().validate_properties(option_bag)
except PropertiesOptionError:
continue
@ -508,7 +510,7 @@ class SubConfig(object):
subpath = path
opt = subconfig.cfgimpl_get_description().impl_getchild(subpath,
config_bag,
subconfig)
subconfig.cfgimpl_get_path())
soption_bag = OptionBag()
soption_bag.set_option(opt,
path,
@ -874,7 +876,7 @@ class KernelGroupConfig(_CommonConfig):
cconfig_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name,
cconfig_bag,
child)
child.cfgimpl_get_path())
option_bag = OptionBag()
option_bag.set_option(option,
path,
@ -919,7 +921,8 @@ class KernelGroupConfig(_CommonConfig):
config_bag=config_bag,
raise_if_not_found=raise_if_not_found))
byname = None
byoption = self.cfgimpl_get_description().impl_get_opt_by_path(bypath)
byoption = self.cfgimpl_get_description().impl_get_opt_by_path(bypath,
config_bag)
ret = []
for child in self._impl_children:
@ -1040,7 +1043,8 @@ class KernelMetaConfig(KernelGroupConfig):
if force_default and force_dont_change_value:
raise ValueError(_('force_default and force_dont_change_value'
' cannot be set together'))
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path)
opt = self.cfgimpl_get_description().impl_get_opt_by_path(path,
config_bag)
for child in self._impl_children:
cconfig_bag = config_bag.copy()
cconfig_bag.context = child
@ -1048,7 +1052,7 @@ class KernelMetaConfig(KernelGroupConfig):
cconfig_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name,
cconfig_bag,
child)
child.cfgimpl_get_path())
option_bag = OptionBag()
option_bag.set_option(option,
path,
@ -1080,7 +1084,7 @@ class KernelMetaConfig(KernelGroupConfig):
config_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name,
config_bag,
self)
self.cfgimpl_get_path())
option_bag = OptionBag()
option_bag.set_option(option,
path,
@ -1102,7 +1106,7 @@ class KernelMetaConfig(KernelGroupConfig):
config_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name,
config_bag,
self)
self.cfgimpl_get_path())
option_bag = OptionBag()
option_bag.set_option(option,
path,

View file

@ -30,7 +30,7 @@ from ..error import ConfigError, ConflictError
class CacheOptionDescription(BaseOption):
__slots__ = ('_cache_paths', '_cache_consistencies', '_cache_force_store_values')
__slots__ = ('_cache_consistencies', '_cache_force_store_values')
def _build_cache(self,
config,
@ -154,7 +154,7 @@ class CacheOptionDescription(BaseOption):
self._set_readonly()
def impl_already_build_caches(self):
if hasattr(self, '_cache_paths'):
if hasattr(self, '_cache_consistencies'):
return True
return False
@ -192,11 +192,10 @@ class CacheOptionDescription(BaseOption):
values._p_.commit()
def _build_cache_option(self,
_currpath=None,
cache_path=None,
cache_option=None):
_currpath=None):
if self.impl_is_readonly() or (_currpath is None and getattr(self, '_cache_paths', None) is not None):
if self.impl_is_readonly() or \
(_currpath is None and getattr(self, '_cache_consistencies', None) is not None):
# cache already set
return
if _currpath is None:
@ -204,24 +203,17 @@ class CacheOptionDescription(BaseOption):
_currpath = []
else:
save = False
if cache_path is None:
cache_path = []
cache_option = []
for option in self.impl_getchildren(config_bag=undefined,
dyn=False):
attr = option.impl_getname()
path = str('.'.join(_currpath + [attr]))
cache_option.append(option)
cache_path.append(path)
option._path = path
if option.impl_is_optiondescription():
_currpath.append(attr)
option._build_cache_option(_currpath,
cache_path,
cache_option)
option._build_cache_option(_currpath)
_currpath.pop()
if save:
self._cache_paths = (tuple(cache_option), tuple(cache_path))
if save and not hasattr(self, '_cache_consistencies'):
self._cache_consistencies = None
class OptionDescriptionWalk(CacheOptionDescription):
@ -248,57 +240,43 @@ class OptionDescriptionWalk(CacheOptionDescription):
bytype,
byname,
_subpath,
config_bag):
def _filter_by_type(path,
option):
if isinstance(option,
bytype):
return _filter_by_name(path, option)
config_bag,
self_opt=None):
if self_opt is None:
self_opt = self
def _filter_by_name(option):
return byname is None or option.impl_getname() == byname
def _filter_by_name(path,
option):
name = option.impl_getname()
if option.issubdyn():
if byname.startswith(name):
option_bag = OptionBag()
option_bag.set_option(option,
path,
None,
config_bag)
for doption in self.build_dynoptions(option_bag):
if byname == doption.impl_getname():
dpath = doption.impl_getpath()
return (dpath, doption)
elif byname == name:
return (path, option)
def _filter(path, option):
if bytype is not None:
return _filter_by_type(path, option)
return _filter_by_name(path, option)
opts, paths = self._cache_paths
for index, option in enumerate(opts):
for option in self_opt.impl_getchildren(config_bag):
if _subpath is None:
path = option.impl_getname()
else:
path = _subpath + '.' + option.impl_getname()
if option.impl_is_optiondescription():
continue
path = paths[index]
if _subpath is not None and not path.startswith(_subpath + '.'):
continue
ret = _filter(path, option)
if ret:
yield ret
for subopt in option.impl_get_options_paths(bytype,
byname,
path,
config_bag):
yield subopt
else:
if bytype is not None:
if isinstance(option, bytype) and \
_filter_by_name(option):
yield (path, option)
elif _filter_by_name(option):
yield (path, option)
def impl_getchild(self,
name,
config_bag,
subconfig):
subpath):
if name in self._children[0]:
child = self._children[1][self._children[0].index(name)]
if not child.impl_is_dynoptiondescription():
return child
else:
child = self._impl_search_dynchild(name,
subconfig,
subpath,
config_bag)
if child:
return child
@ -307,12 +285,19 @@ class OptionDescriptionWalk(CacheOptionDescription):
'').format(name, self.impl_getname()))
def impl_get_opt_by_path(self,
path):
return self._cache_paths[0][self._cache_paths[1].index(path)]
def impl_get_path_by_opt(self,
opt):
return self._cache_paths[1][self._cache_paths[0].index(opt)]
path,
config_bag):
opt = self
subpath = None
for step in path.split('.'):
opt = opt.impl_getchild(step,
config_bag,
subpath)
if subpath is None:
subpath = step
else:
subpath += '.' + step
return opt
def impl_getchildren(self,
config_bag,
@ -347,7 +332,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
def _impl_search_dynchild(self,
name,
subconfig,
subpath,
config_bag):
for child in self._impl_st_getchildren(only_dyn=True):
#sconfig_bag = config_bag.copy('nooption')
@ -356,13 +341,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
if name.startswith(cname):
option_bag = OptionBag()
option_bag.set_option(child,
subconfig.cfgimpl_get_path(),
subpath,
None,
config_bag)
for value in child.impl_get_suffixes(option_bag):
if name == cname + value:
return SynDynOptionDescription(child,
subconfig.cfgimpl_get_path(),
subpath,
value)
def _impl_get_dynchild(self,
@ -424,7 +409,7 @@ class OptionDescription(OptionDescriptionWalk):
'the dynoptiondescription\'s name "{}"').format(child, dynopt))
old = child
self._children = children_
self._cache_consistencies = None
#self._cache_consistencies = None
# the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default

View file

@ -44,14 +44,14 @@ class SynDynOptionDescription(object):
def impl_getchild(self,
name,
config_bag,
subconfig):
subpath):
try:
if name.endswith(self._suffix):
oname = name[:-len(self._suffix)]
child = self._children[1][self._children[0].index(oname)]
return self._impl_get_dynchild(child,
self._suffix,
subconfig.cfgimpl_get_path())
subpath)
except ValueError:
# when oname not in self._children
pass
@ -72,6 +72,17 @@ class SynDynOptionDescription(object):
self._suffix,
subpath))
def impl_get_options_paths(self,
bytype,
byname,
_subpath,
config_bag):
return self._opt.impl_get_options_paths(bytype,
byname,
_subpath,
config_bag,
self)
def impl_getpath(self):
subpath = self._subpath
if subpath != '':

View file

@ -175,7 +175,6 @@ class ConfigBag:
'permissives', # permissives for current context
)
def __init__(self, context, **kwargs):
#self.force_permissive = False
self.context = context
for key, value in kwargs.items():
setattr(self, key, value)
@ -196,10 +195,17 @@ class ConfigBag:
self.properties = frozenset(self.properties | {'permissive'})
def __delattr__(self, key):
if key == 'properties':
if key in ['properties', 'permissives']:
try:
super().__delattr__(key)
except AttributeError:
pass
return
raise KeyError('unknown key {} for ConfigBag'.format(key))
#def __setattr__(self, key, value):
# super().__setattr__(key, value)
def copy(self):
kwargs = {}
for key in self.__slots__: