add force_permissive to config __iter__

This commit is contained in:
Emmanuel Garette 2014-10-26 10:26:23 +01:00
parent a130cff4bf
commit 4310d59991
5 changed files with 29 additions and 8 deletions

View File

@ -3,6 +3,7 @@ Sun Oct 26 08:50:38 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
must be 'default' check property when tried to change owner must be 'default' check property when tried to change owner
* bad characters in DomainnameOption could be in warning level * bad characters in DomainnameOption could be in warning level
* frozen with force_default_on_freeze can change owner * frozen with force_default_on_freeze can change owner
* add force_permissive to config __iter__
Sat Oct 25 22:48:08 2014 +0200 Emmanuel Garette <egarette@cadoles.com> Sat Oct 25 22:48:08 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
* cannot add unvalaible consistency for an option * cannot add unvalaible consistency for an option

View File

@ -236,7 +236,7 @@ def test_values_not_setitem():
d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5]) d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5])
root = OptionDescription('root', '', [d1]) root = OptionDescription('root', '', [d1])
config = Config(root) config = Config(root)
raises(ValueError, "config.cfgimpl_get_values()[g1] = 2") raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2")
def test_duplicated_option(): def test_duplicated_option():

View File

@ -18,12 +18,15 @@ def make_description():
default=False) default=False)
mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur", mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur",
default=False) default=False)
mode_conteneur_actif2 = BoolOption('mode_conteneur_actif2', "le serveur est en mode conteneur2",
default=False, properties=('hidden',))
adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True) adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True)
time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur', time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur',
('Paris', 'Londres'), 'Paris') ('Paris', 'Londres'), 'Paris')
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé") ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", properties=('test_perm',))
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", properties=('test_perm',))
master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
interface1 = OptionDescription('interface1', '', [master]) interface1 = OptionDescription('interface1', '', [master])
@ -31,8 +34,8 @@ def make_description():
general = OptionDescription('general', '', [numero_etab, nom_machine, general = OptionDescription('general', '', [numero_etab, nom_machine,
nombre_interfaces, activer_proxy_client, nombre_interfaces, activer_proxy_client,
mode_conteneur_actif, adresse_serveur_ntp, mode_conteneur_actif, mode_conteneur_actif2,
time_zone]) adresse_serveur_ntp, time_zone])
general.impl_set_group_type(groups.family) general.impl_set_group_type(groups.family)
new = OptionDescription('new', '', [], properties=('hidden',)) new = OptionDescription('new', '', [], properties=('hidden',))
new.impl_set_group_type(groups.family) new.impl_set_group_type(groups.family)
@ -102,6 +105,22 @@ def test_iter_on_groups():
def test_iter_on_groups_force_permissive(): def test_iter_on_groups_force_permissive():
descr = make_description()
config = Config(descr)
config.read_write()
config.cfgimpl_get_settings().setpermissive(('hidden',))
result = list(config.creole.general.__iter__(force_permissive=True))
group_names = [res[0] for res in result]
ass = ['numero_etab', 'nom_machine', 'nombre_interfaces',
'activer_proxy_client', 'mode_conteneur_actif',
'mode_conteneur_actif2', 'serveur_ntp', 'time_zone']
assert group_names == ass
group_names = [res[0] for res in config.creole.general]
ass.remove('mode_conteneur_actif2')
assert group_names == ass
def test_iter_group_on_groups_force_permissive():
descr = make_description() descr = make_description()
config = Config(descr) config = Config(descr)
config.read_write() config.read_write()

View File

@ -97,7 +97,7 @@ class SubConfig(object):
# return not self == other # return not self == other
# ______________________________________________________________________ # ______________________________________________________________________
def __iter__(self): def __iter__(self, force_permissive=False):
"""Pythonesque way of parsing group's ordered options. """Pythonesque way of parsing group's ordered options.
iteration only on Options (not OptionDescriptions)""" iteration only on Options (not OptionDescriptions)"""
for child in self.cfgimpl_get_description()._impl_getchildren( for child in self.cfgimpl_get_description()._impl_getchildren(
@ -105,7 +105,8 @@ class SubConfig(object):
if not child.impl_is_optiondescription(): if not child.impl_is_optiondescription():
try: try:
name = child.impl_getname() name = child.impl_getname()
yield name, getattr(self, name) yield name, self.getattr(name,
force_permissive=force_permissive)
except GeneratorExit: # pragma: optional cover except GeneratorExit: # pragma: optional cover
raise StopIteration raise StopIteration
except PropertiesOptionError: # pragma: optional cover except PropertiesOptionError: # pragma: optional cover

View File

@ -300,7 +300,7 @@ class Values(object):
return value return value
def __setitem__(self, opt, value): # pragma: optional cover def __setitem__(self, opt, value): # pragma: optional cover
raise ValueError(_('you should only set value with config')) raise ConfigError(_('you should only set value with config'))
def setitem(self, opt, value, path, force_permissive=False, def setitem(self, opt, value, path, force_permissive=False,
is_write=True): is_write=True):