parsing_group
This commit is contained in:
@ -80,7 +80,22 @@ def display_count():
|
||||
MOD_COUNT_TIME = deepcopy(COUNT_TIME)
|
||||
|
||||
|
||||
class CommonTiramisuOption(object):
|
||||
class CommonTiramisu(object):
|
||||
allow_optiondescription = True
|
||||
|
||||
def get_option(self):
|
||||
option = self.config_bag.option
|
||||
if option is None:
|
||||
option = self.subconfig.cfgimpl_get_description().impl_getchild(self.name,
|
||||
self.config_bag,
|
||||
self.subconfig)
|
||||
self.config_bag.option = option
|
||||
if not self.allow_optiondescription and option.impl_is_optiondescription():
|
||||
raise APIError(_('option must not be an optiondescription'))
|
||||
return option
|
||||
|
||||
|
||||
class CommonTiramisuOption(CommonTiramisu):
|
||||
icon = '\u2937'
|
||||
tmpl_help = u' {} {}: {}'
|
||||
allow_unrestraint = False
|
||||
@ -123,17 +138,6 @@ class CommonTiramisuOption(object):
|
||||
else:
|
||||
super(CommonTiramisuOption, self).__getattribute__(name)
|
||||
|
||||
def get_option(self):
|
||||
option = self.config_bag.option
|
||||
if option is None:
|
||||
option = self.subconfig.cfgimpl_get_description().impl_getchild(self.name,
|
||||
self.config_bag,
|
||||
self.subconfig)
|
||||
self.config_bag.option = option
|
||||
if not self.allow_optiondescription and option.impl_is_optiondescription():
|
||||
raise APIError(_('option must not be an optiondescription'))
|
||||
return option
|
||||
|
||||
def _help(self):
|
||||
txt = []
|
||||
for func_name in dir(self):
|
||||
@ -290,6 +294,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
|
||||
@count
|
||||
def add(self, prop):
|
||||
#FIXME not index !!
|
||||
self.get_option()
|
||||
self.settings.addproperty(self.path,
|
||||
prop,
|
||||
@ -402,12 +407,10 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
self.config_bag)
|
||||
|
||||
@count
|
||||
def pop(self, index):
|
||||
def _pop(self, index):
|
||||
"""pop value for a specified master values
|
||||
"""
|
||||
self.get_option()
|
||||
self._test_slave_index()
|
||||
#FIXME only for master
|
||||
self.config_bag.config.delattr(self.path,
|
||||
index,
|
||||
self.config_bag)
|
||||
@ -422,8 +425,7 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
self.config_bag)
|
||||
|
||||
@count
|
||||
def len(self):
|
||||
#FIXME only for slave
|
||||
def _len(self):
|
||||
self.get_option()
|
||||
subconfig_path = self.path.rsplit('.', 1)[0]
|
||||
subconfig = self.config.getattr(subconfig_path,
|
||||
@ -432,11 +434,12 @@ class TiramisuOptionValue(CommonTiramisuOption):
|
||||
return subconfig.cfgimpl_get_length()
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name == 'list':
|
||||
self.get_option()
|
||||
if isinstance(self.config_bag.option, ChoiceOption):
|
||||
return self._list
|
||||
raise APIError(_('{} allowed only for choiceoption').format(name))
|
||||
if name == 'list' and isinstance(self.get_option(), ChoiceOption):
|
||||
return self._list
|
||||
elif name == 'pop' and self.get_option().impl_is_master_slaves('master'):
|
||||
return self._pop
|
||||
elif name == 'len' and self.get_option().impl_is_master_slaves('slave'):
|
||||
return self._len
|
||||
raise APIError(_('{} is unknown').format(name))
|
||||
|
||||
@count
|
||||
@ -452,7 +455,7 @@ def registers(registers, prefix):
|
||||
registers[func_name] = module
|
||||
|
||||
|
||||
class TiramisuOption(object):
|
||||
class TiramisuOption(CommonTiramisu):
|
||||
icon = '\u2937'
|
||||
tmpl_help = ' {} {}: {}'
|
||||
|
||||
@ -488,15 +491,21 @@ class TiramisuOption(object):
|
||||
self.config_bag)
|
||||
elif subfunc == 'help':
|
||||
return self._help()
|
||||
elif subfunc == 'make_dict' and self.get_option().impl_is_optiondescription():
|
||||
return self._make_dict
|
||||
elif subfunc == 'list' and self.get_option().impl_is_optiondescription():
|
||||
return self._list
|
||||
elif subfunc == 'group_type' and self.get_option().impl_is_optiondescription():
|
||||
return self._group_type
|
||||
else:
|
||||
raise APIError(_('please specify a valid sub function ({})').format(subfunc))
|
||||
|
||||
@count
|
||||
def make_dict(self,
|
||||
flatten=False,
|
||||
withvalue=undefined,
|
||||
withoption=None,
|
||||
fullpath=False):
|
||||
def _make_dict(self,
|
||||
flatten=False,
|
||||
withvalue=undefined,
|
||||
withoption=None,
|
||||
fullpath=False):
|
||||
return self.config_bag.config.getattr(self.path,
|
||||
None,
|
||||
self.config_bag).make_dict(config_bag=self.config_bag,
|
||||
@ -505,6 +514,25 @@ class TiramisuOption(object):
|
||||
withoption=withoption,
|
||||
withvalue=withvalue)
|
||||
|
||||
@count
|
||||
def group_type(self):
|
||||
return self.get_option().impl_get_group_type()
|
||||
|
||||
@count
|
||||
def _list(self, type='all', group_type=None):
|
||||
if type == 'optiondescription':
|
||||
return self.config_bag.config.getattr(self.path,
|
||||
None,
|
||||
self.config_bag
|
||||
).iter_groups(self.config_bag, group_type)
|
||||
elif type == 'all':
|
||||
return self.config_bag.config.getattr(self.path,
|
||||
None,
|
||||
self.config_bag
|
||||
).cfgimpl_get_children(self.config_bag)
|
||||
else:
|
||||
raise APIError(_('unknown list type {}').format(type))
|
||||
|
||||
|
||||
class TiramisuContext(object):
|
||||
def __init__(self,
|
||||
@ -645,6 +673,15 @@ class TiramisuContextOption(TiramisuContext):
|
||||
withoption=withoption,
|
||||
withvalue=withvalue)
|
||||
|
||||
@count
|
||||
def list(self, type='all', group_type=None):
|
||||
if type == 'optiondescription':
|
||||
return self.config_bag.config.iter_groups(self.config_bag, group_type)
|
||||
elif type == 'all':
|
||||
return self.config_bag.config.cfgimpl_get_children(self.config_bag)
|
||||
else:
|
||||
raise APIError(_('unknown list type {}').format(type))
|
||||
|
||||
|
||||
class TiramisuDispatcherOption(TiramisuContextOption):
|
||||
def __call__(self, path, index=None):
|
||||
|
@ -26,6 +26,7 @@ from copy import copy
|
||||
|
||||
from .error import PropertiesOptionError, ConfigError, ConflictError, SlaveError
|
||||
from .option.syndynoptiondescription import SynDynOptionDescription
|
||||
from .option.masterslave import MasterSlaves
|
||||
from .option.baseoption import BaseOption, valid_name
|
||||
from .setting import ConfigBag, groups, Settings, undefined
|
||||
from .storage import get_storages, get_default_values_storages
|
||||
@ -198,9 +199,8 @@ class SubConfig(object):
|
||||
# pass # option with properties
|
||||
|
||||
def iter_groups(self,
|
||||
setting_properties,
|
||||
group_type=None,
|
||||
force_permissive=False):
|
||||
config_bag,
|
||||
group_type=None):
|
||||
"""iteration on groups objects only.
|
||||
All groups are returned if `group_type` is `None`, otherwise the groups
|
||||
can be filtered by categories (families, or whatever).
|
||||
@ -215,16 +215,34 @@ class SubConfig(object):
|
||||
context = self._cfgimpl_get_context()
|
||||
for child in self.cfgimpl_get_description().impl_getchildren(config_bag):
|
||||
if child.impl_is_optiondescription():
|
||||
nconfig_bag = config_bag.copy('nooption')
|
||||
nconfig_bag.option = child
|
||||
try:
|
||||
if group_type is None or (group_type is not None and
|
||||
child.impl_get_group_type()
|
||||
== group_type):
|
||||
name = child.impl_getname()
|
||||
yield name, self.getattr(name,
|
||||
force_permissive=force_permissive,
|
||||
setting_properties=setting_properties)
|
||||
None,
|
||||
nconfig_bag)
|
||||
except PropertiesOptionError: # pragma: optional cover
|
||||
pass
|
||||
|
||||
def cfgimpl_get_children(self, config_bag):
|
||||
context = self._cfgimpl_get_context()
|
||||
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag):
|
||||
nconfig_bag = config_bag.copy('nooption')
|
||||
nconfig_bag.option = opt
|
||||
name = opt.impl_getname()
|
||||
subpath = self._get_subpath(name)
|
||||
try:
|
||||
context.cfgimpl_get_settings().validate_properties(subpath,
|
||||
None,
|
||||
nconfig_bag)
|
||||
yield name
|
||||
except PropertiesOptionError:
|
||||
pass
|
||||
|
||||
# ______________________________________________________________________
|
||||
|
||||
# def __str__(self):
|
||||
@ -300,9 +318,9 @@ class SubConfig(object):
|
||||
context.cfgimpl_get_settings().validate_properties(path,
|
||||
index,
|
||||
config_bag)
|
||||
context.cfgimpl_get_description().impl_validate_value(config_bag.option,
|
||||
value,
|
||||
self)
|
||||
self.cfgimpl_get_description().impl_validate_value(config_bag.option,
|
||||
value,
|
||||
self)
|
||||
return context.cfgimpl_get_values().setvalue(path,
|
||||
index,
|
||||
value,
|
||||
@ -408,7 +426,7 @@ class SubConfig(object):
|
||||
'').format(subpath))
|
||||
length = self.cfgimpl_get_length()
|
||||
if index is not None and index >= length:
|
||||
raise IndexError(_('index "{}" is higher than the master length "{}" '
|
||||
raise SlaveError(_('index "{}" is higher than the master length "{}" '
|
||||
'for option "{}"').format(index,
|
||||
length,
|
||||
option.impl_get_display_name()))
|
||||
@ -872,6 +890,8 @@ class Config(_CommonConfig):
|
||||
:type persistent: `boolean`
|
||||
"""
|
||||
self._impl_meta = None
|
||||
if isinstance(descr, MasterSlaves):
|
||||
raise ConfigError(_('cannot set MasterSlaves object has root optiondescription'))
|
||||
if force_settings is not None and force_values is not None:
|
||||
if isinstance(force_settings, tuple):
|
||||
self._impl_settings = Settings(self,
|
||||
|
@ -172,8 +172,8 @@ class MasterSlaves(OptionDescription):
|
||||
context):
|
||||
if option.impl_is_master_slaves('master') and isinstance(value, list):
|
||||
if len(value) < context._impl_length:
|
||||
raise ValueError(_('cannot reduce length of master "{}"'
|
||||
'').format(option.impl_get_display_name()))
|
||||
raise SlaveError(_('cannot reduce length of the master "{}"'
|
||||
'').format(option.impl_get_display_name()))
|
||||
|
||||
def is_masterslaves(self):
|
||||
return True
|
||||
|
Reference in New Issue
Block a user