support multiple metaconfig and prefix
This commit is contained in:
parent
77a77dd01c
commit
f6a9b88795
|
@ -711,12 +711,12 @@ def test_meta_properties_meta_copy():
|
||||||
conf2 = Config(interface1, session_id='conf2')
|
conf2 = Config(interface1, session_id='conf2')
|
||||||
conf1.property.read_write()
|
conf1.property.read_write()
|
||||||
conf2.property.read_write()
|
conf2.property.read_write()
|
||||||
meta = MetaConfig([conf1, conf2])
|
meta = MetaConfig([conf1, conf2], session_id='meta1')
|
||||||
meta.property.read_write()
|
meta.property.read_write()
|
||||||
|
|
||||||
conf3 = meta.config('conf1').config.copy(session_id='conf3')
|
conf3 = meta.config('conf1').config.copy(session_id='conf3')
|
||||||
meta2 = conf3.config.meta()
|
meta2 = conf3.config.metaconfig()
|
||||||
assert meta != meta2
|
assert meta.config.name() == meta2.config.name()
|
||||||
|
|
||||||
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
assert meta.config('conf1').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
||||||
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
assert meta.config('conf2').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
||||||
|
@ -744,7 +744,7 @@ def test_meta_properties_meta_deepcopy():
|
||||||
meta.permissive.set(frozenset({'hidden'}))
|
meta.permissive.set(frozenset({'hidden'}))
|
||||||
meta.property.read_write()
|
meta.property.read_write()
|
||||||
|
|
||||||
meta2 = meta.config('conf1').config.deepcopy('conf3')
|
meta2 = meta.config('conf1').config.deepcopy(session_id='conf3')
|
||||||
assert meta != meta2
|
assert meta != meta2
|
||||||
assert meta.permissive.get() == meta2.permissive.get()
|
assert meta.permissive.get() == meta2.permissive.get()
|
||||||
|
|
||||||
|
@ -761,6 +761,22 @@ def test_meta_properties_meta_deepcopy():
|
||||||
assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
assert meta2.config('conf3').value.dict() == {'ip_admin_eth0': ['192.168.1.1']}
|
||||||
|
|
||||||
|
|
||||||
|
def test_meta_properties_submeta_deepcopy():
|
||||||
|
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||||
|
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True,
|
||||||
|
properties=('disabled',))
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
conf1 = Config(interface1, session_id='conf1')
|
||||||
|
conf1.property.read_write()
|
||||||
|
meta1 = MetaConfig([conf1], session_id='meta1')
|
||||||
|
meta2 = MetaConfig([meta1], session_id='meta2')
|
||||||
|
meta_copy = conf1.config.deepcopy(session_id='conf2',
|
||||||
|
metaconfig_prefix='copy_')
|
||||||
|
assert meta_copy.config.name() == 'copy_meta2'
|
||||||
|
assert meta_copy.config('copy_meta1').config.name() == 'copy_meta1'
|
||||||
|
assert meta_copy.config('copy_meta1').config('conf2').config.name() == 'conf2'
|
||||||
|
|
||||||
|
|
||||||
def test_meta_properties_meta_set_value():
|
def test_meta_properties_meta_set_value():
|
||||||
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
ip_admin_eth0 = NetworkOption('ip_admin_eth0', "ip", multi=True, default=['192.168.1.1'])
|
||||||
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
|
netmask_admin_eth0 = NetmaskOption('netmask_admin_eth0', "mask", multi=True, properties=('disabled',))
|
||||||
|
|
|
@ -990,13 +990,15 @@ class TiramisuContextConfig(TiramisuContext):
|
||||||
def _c_deepcopy(self,
|
def _c_deepcopy(self,
|
||||||
session_id=None,
|
session_id=None,
|
||||||
persistent=False,
|
persistent=False,
|
||||||
storage=None):
|
storage=None,
|
||||||
|
metaconfig_prefix=None):
|
||||||
return Config(self.config_bag.context.duplicate(session_id,
|
return Config(self.config_bag.context.duplicate(session_id,
|
||||||
persistent=persistent,
|
persistent=persistent,
|
||||||
storage=storage,
|
storage=storage,
|
||||||
|
metaconfig_prefix=metaconfig_prefix,
|
||||||
deep=True))
|
deep=True))
|
||||||
|
|
||||||
def _c_meta(self):
|
def _c_metaconfig(self):
|
||||||
return Config(self.config_bag.context.cfgimpl_get_meta())
|
return Config(self.config_bag.context.cfgimpl_get_meta())
|
||||||
|
|
||||||
def _m_new(self,
|
def _m_new(self,
|
||||||
|
|
|
@ -682,9 +682,11 @@ class _CommonConfig(SubConfig):
|
||||||
force_settings=None,
|
force_settings=None,
|
||||||
storage=None,
|
storage=None,
|
||||||
persistent=False,
|
persistent=False,
|
||||||
|
metaconfig_prefix=None,
|
||||||
|
child=None,
|
||||||
deep=False):
|
deep=False):
|
||||||
if isinstance(self, KernelConfig):
|
if isinstance(self, KernelConfig):
|
||||||
config = KernelConfig(self._impl_descr,
|
duplicated_config = KernelConfig(self._impl_descr,
|
||||||
_duplicate=True,
|
_duplicate=True,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
force_values=force_values,
|
force_values=force_values,
|
||||||
|
@ -692,7 +694,9 @@ class _CommonConfig(SubConfig):
|
||||||
persistent=persistent,
|
persistent=persistent,
|
||||||
storage=storage)
|
storage=storage)
|
||||||
elif isinstance(self, KernelMetaConfig):
|
elif isinstance(self, KernelMetaConfig):
|
||||||
config = KernelMetaConfig([],
|
if session_id is None and metaconfig_prefix is not None:
|
||||||
|
session_id = metaconfig_prefix + self.impl_getname()
|
||||||
|
duplicated_config = KernelMetaConfig([],
|
||||||
_duplicate=True,
|
_duplicate=True,
|
||||||
optiondescription=self._impl_descr,
|
optiondescription=self._impl_descr,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
|
@ -701,22 +705,26 @@ class _CommonConfig(SubConfig):
|
||||||
persistent=persistent,
|
persistent=persistent,
|
||||||
storage=storage)
|
storage=storage)
|
||||||
else:
|
else:
|
||||||
raise Exception('hu?')
|
raise Exception(_('unknown type'))
|
||||||
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
|
duplicated_config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation())
|
||||||
config.cfgimpl_get_settings()._p_.importation(self.cfgimpl_get_settings(
|
duplicated_config.cfgimpl_get_settings()._p_.importation(self.cfgimpl_get_settings(
|
||||||
)._p_.exportation())
|
)._p_.exportation())
|
||||||
config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings(
|
duplicated_config.cfgimpl_get_settings()._pp_.importation(self.cfgimpl_get_settings(
|
||||||
)._pp_.exportation())
|
)._pp_.exportation())
|
||||||
|
if child is not None:
|
||||||
|
duplicated_config._impl_children.append(child)
|
||||||
|
child._impl_meta = weakref.ref(duplicated_config)
|
||||||
if self._impl_meta:
|
if self._impl_meta:
|
||||||
if deep:
|
if deep:
|
||||||
meta = self._impl_meta().duplicate(deep=deep, storage=storage, persistent=persistent)
|
duplicated_config = self._impl_meta().duplicate(deep=deep,
|
||||||
meta._impl_children.append(config)
|
storage=storage,
|
||||||
config._impl_meta = weakref.ref(meta)
|
metaconfig_prefix=metaconfig_prefix,
|
||||||
config = meta
|
child=duplicated_config,
|
||||||
|
persistent=persistent)
|
||||||
else:
|
else:
|
||||||
config._impl_meta = self._impl_meta
|
duplicated_config._impl_meta = self._impl_meta
|
||||||
config._impl_meta()._impl_children.append(config)
|
self._impl_meta()._impl_children.append(duplicated_config)
|
||||||
return config
|
return duplicated_config
|
||||||
|
|
||||||
|
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
Loading…
Reference in New Issue