config is context in ConfigBag

This commit is contained in:
Emmanuel Garette 2018-08-02 22:35:40 +02:00
parent c46480a7eb
commit 81666b6303
12 changed files with 123 additions and 270 deletions

View File

@ -30,63 +30,9 @@ from .option import ChoiceOption, OptionDescription
TIRAMISU_VERSION = 3 TIRAMISU_VERSION = 3
#try:
# from .value import Multi
#except:
# Multi = list
COUNT_TIME = False
#COUNT_TIME = {}
EXCLUDE_HELP = ('help', '_get_option', '_test_slave_index') EXCLUDE_HELP = ('help', '_get_option', '_test_slave_index')
def count(func):
global MOD_COUNT_TIME
class_name = func.__str__().split()[1].split('.')[0]
func_name = func.__name__
def wrapper(*args, **kwargs): # pragma: no cover
time1 = time()
ret = func(*args, **kwargs)
time2 = time()
diff = (time2 - time1) * 1000.0
MOD_COUNT_TIME[class_name][func_name]['max'] = max(MOD_COUNT_TIME[class_name][func_name]['max'], diff)
MOD_COUNT_TIME[class_name][func_name]['min'] = min(MOD_COUNT_TIME[class_name][func_name]['min'], diff)
MOD_COUNT_TIME[class_name][func_name]['total'] += diff
MOD_COUNT_TIME[class_name][func_name]['nb'] += 1
#print('%s function took %0.3f ms' % (func_name, diff))
#print(COUNT_TIME)
return ret
if COUNT_TIME is not False: # pragma: no cover
COUNT_TIME.setdefault(class_name, {})
COUNT_TIME[class_name][func_name] = {'max': 0,
'min': 1000,
'nb': 0,
'total': 0}
MOD_COUNT_TIME = deepcopy(COUNT_TIME)
return wrapper
return func
def display_count():
if COUNT_TIME is not False: # pragma: no cover
global MOD_COUNT_TIME
#print(MOD_COUNT_TIME)
print()
for class_name in MOD_COUNT_TIME:
print('>', class_name)
for func in MOD_COUNT_TIME[class_name]:
print('=>', func)
print('==> nb:', MOD_COUNT_TIME[class_name][func]['nb'])
if MOD_COUNT_TIME[class_name][func]['nb'] != 0:
print('==> min:', MOD_COUNT_TIME[class_name][func]['min'])
print('==> max:', MOD_COUNT_TIME[class_name][func]['max'])
print('==> moy:', MOD_COUNT_TIME[class_name][func]['total'] / MOD_COUNT_TIME[class_name][func]['nb'])
MOD_COUNT_TIME = deepcopy(COUNT_TIME)
class TiramisuHelp: class TiramisuHelp:
icon = '\u2937' icon = '\u2937'
tmpl_help = '{0}{1} {2}: \n{0} {3}\n' tmpl_help = '{0}{1} {2}: \n{0} {3}\n'
@ -169,8 +115,6 @@ class CommonTiramisu(TiramisuHelp):
self._path, self._path,
self.index, self.index,
self.config_bag) self.config_bag)
if self.config_bag.setting_properties:
self.config_bag.config.cfgimpl_get_settings().validate_properties(self.option_bag)
if self.index is not None: if self.index is not None:
if option.impl_is_optiondescription() or not option.impl_is_master_slaves('slave'): if option.impl_is_optiondescription() or not option.impl_is_master_slaves('slave'):
raise APIError('index must be set only with a slave option') raise APIError('index must be set only with a slave option')
@ -225,48 +169,40 @@ class TiramisuOptionOption(CommonTiramisuOption):
allow_optiondescription = True allow_optiondescription = True
slave_need_index = False slave_need_index = False
@count
def get(self): def get(self):
"""get Tiramisu option""" """get Tiramisu option"""
return self._get_option() return self._get_option()
@count
def _ismulti(self): def _ismulti(self):
"""test if option could have multi value""" """test if option could have multi value"""
option = self._get_option() option = self._get_option()
return option.impl_is_multi() return option.impl_is_multi()
@count
def _issubmulti(self): def _issubmulti(self):
"""test if option could have submulti value""" """test if option could have submulti value"""
option = self._get_option() option = self._get_option()
return option.impl_is_submulti() return option.impl_is_submulti()
@count
def ismasterslaves(self): def ismasterslaves(self):
"""test if option is a master or a slave""" """test if option is a master or a slave"""
option = self._get_option() option = self._get_option()
return option.impl_is_master_slaves() return option.impl_is_master_slaves()
@count
def _ismaster(self): def _ismaster(self):
"""test if option is a master""" """test if option is a master"""
option = self._get_option() option = self._get_option()
return option.impl_is_master_slaves('master') return option.impl_is_master_slaves('master')
@count
def _isslave(self): def _isslave(self):
"""test if option is a slave""" """test if option is a slave"""
option = self._get_option() option = self._get_option()
return option.impl_is_master_slaves('slave') return option.impl_is_master_slaves('slave')
@count
def doc(self): def doc(self):
"""get option document""" """get option document"""
option = self._get_option() option = self._get_option()
return option.impl_get_display_name() return option.impl_get_display_name()
@count
def name(self): def name(self):
"""get option name""" """get option name"""
self._get_option() self._get_option()
@ -277,37 +213,31 @@ class TiramisuOptionOption(CommonTiramisuOption):
self._get_option() self._get_option()
return self._path return self._path
@count
def _default(self): def _default(self):
"""get default value for an option (not for optiondescription)""" """get default value for an option (not for optiondescription)"""
option = self._get_option() option = self._get_option()
return option.impl_getdefault() return option.impl_getdefault()
@count
def _defaultmulti(self): def _defaultmulti(self):
"""get default value when added a value for a multi option (not for optiondescription)""" """get default value when added a value for a multi option (not for optiondescription)"""
option = self._get_option() option = self._get_option()
return option.impl_getdefault_multi() return option.impl_getdefault_multi()
@count
def has_dependency(self, self_is_dep=True): def has_dependency(self, self_is_dep=True):
"""test if option has dependency""" """test if option has dependency"""
option = self._get_option() option = self._get_option()
return option.impl_has_dependency(self_is_dep) return option.impl_has_dependency(self_is_dep)
@count
def _consistencies(self): def _consistencies(self):
"""get consistencies for an option (not for optiondescription)""" """get consistencies for an option (not for optiondescription)"""
option = self._get_option() option = self._get_option()
return option.get_consistencies() return option.get_consistencies()
@count
def _callbacks(self): def _callbacks(self):
"""get callbacks for an option (not for optiondescription)""" """get callbacks for an option (not for optiondescription)"""
option = self._get_option() option = self._get_option()
return option.impl_get_callback() return option.impl_get_callback()
@count
def requires(self): def requires(self):
"""get requires for an option""" """get requires for an option"""
option = self._get_option() option = self._get_option()
@ -341,21 +271,18 @@ class TiramisuOptionOwner(CommonTiramisuOption):
config_bag, config_bag,
option_bag) option_bag)
if config_bag: if config_bag:
self.values = self.config_bag.config.cfgimpl_get_values() self.values = self.config_bag.context.cfgimpl_get_values()
@count
def get(self): def get(self):
"""get owner for a specified option""" """get owner for a specified option"""
option = self._get_option() option = self._get_option()
return self.values.getowner(self.option_bag) return self.values.getowner(self.option_bag)
@count
def isdefault(self): def isdefault(self):
"""is option has defaut value""" """is option has defaut value"""
self._get_option() self._get_option()
return self.values.is_default_owner(self.option_bag) return self.values.is_default_owner(self.option_bag)
@count
def set(self, owner): def set(self, owner):
"""get owner for a specified option""" """get owner for a specified option"""
self._get_option() self._get_option()
@ -390,9 +317,8 @@ class TiramisuOptionProperty(CommonTiramisuOption):
config_bag, config_bag,
option_bag) option_bag)
if config_bag: if config_bag:
self.settings = config_bag.config.cfgimpl_get_settings() self.settings = config_bag.context.cfgimpl_get_settings()
@count
def get(self, apply_requires=True): def get(self, apply_requires=True):
"""get properties for an option""" """get properties for an option"""
self._get_option() self._get_option()
@ -403,7 +329,6 @@ class TiramisuOptionProperty(CommonTiramisuOption):
properties = self.option_bag.properties properties = self.option_bag.properties
return set(properties) return set(properties)
@count
def add(self, prop): def add(self, prop):
"""add new property for an option""" """add new property for an option"""
self._get_option() self._get_option()
@ -416,7 +341,6 @@ class TiramisuOptionProperty(CommonTiramisuOption):
props | {prop}, props | {prop},
self.option_bag) self.option_bag)
@count
def pop(self, prop): def pop(self, prop):
"""remove new property for an option""" """remove new property for an option"""
self._get_option() self._get_option()
@ -426,7 +350,6 @@ class TiramisuOptionProperty(CommonTiramisuOption):
props - {prop}, props - {prop},
self.option_bag) self.option_bag)
@count
def reset(self): def reset(self):
"""reset all personalised properties""" """reset all personalised properties"""
self._get_option() self._get_option()
@ -452,9 +375,8 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
config_bag, config_bag,
option_bag) option_bag)
if config_bag: if config_bag:
self.settings = config_bag.config.cfgimpl_get_settings() self.settings = config_bag.context.cfgimpl_get_settings()
@count
def get(self): def get(self):
"""get permissives value""" """get permissives value"""
if TIRAMISU_VERSION == 2: if TIRAMISU_VERSION == 2:
@ -463,14 +385,12 @@ class TiramisuOptionPermissive(CommonTiramisuOption):
args = [self._get_option(), self._path] args = [self._get_option(), self._path]
return self.settings.getpermissive(*args) return self.settings.getpermissive(*args)
@count
def set(self, permissives): def set(self, permissives):
"""set permissives value""" """set permissives value"""
self._get_option() self._get_option()
self.settings.setpermissive(self.option_bag, self.settings.setpermissive(self.option_bag,
permissives=permissives) permissives=permissives)
@count
def reset(self): def reset(self):
"""reset all personalised permissive""" """reset all personalised permissive"""
self.set(frozenset()) self.set(frozenset())
@ -481,44 +401,36 @@ class TiramisuOptionInformation(CommonTiramisuOption):
allow_optiondescription = True allow_optiondescription = True
slave_need_index = False slave_need_index = False
@count
def get(self, name, default=undefined): def get(self, name, default=undefined):
"""get information for a key name""" """get information for a key name"""
option = self._get_option() option = self._get_option()
return option.impl_get_information(name, default) return option.impl_get_information(name, default)
@count
def set(self, name, value): def set(self, name, value):
"""set information for a key name""" """set information for a key name"""
self.config_bag.config.impl_set_information(name, value) self.config_bag.context.impl_set_information(name, value)
@count
def reset(self, name): def reset(self, name):
"""remove information for a key name""" """remove information for a key name"""
self.config_bag.config.impl_del_information(name) self.config_bag.context.impl_del_information(name)
class TiramisuOptionValue(CommonTiramisuOption): class TiramisuOptionValue(CommonTiramisuOption):
"""manager option's value""" """manager option's value"""
slave_need_index = False slave_need_index = False
@count
def get(self): def get(self):
"""get option's value""" """get option's value"""
self._get_option()
self._test_slave_index() self._test_slave_index()
settings = self.config_bag.config.cfgimpl_get_settings() return self.subconfig.getattr(self._name,
value = self.subconfig.getattr(self._name,
self.option_bag) self.option_bag)
#if isinstance(value, Multi):
# value = list(value)
return value
@count
def set(self, value): def set(self, value):
"""set a value for a specified option""" """set a value for a specified option"""
self._get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
values = self.config_bag.config.cfgimpl_get_values() values = self.config_bag.context.cfgimpl_get_values()
if isinstance(value, list): if isinstance(value, list):
while undefined in value: while undefined in value:
idx = value.index(undefined) idx = value.index(undefined)
@ -534,25 +446,21 @@ class TiramisuOptionValue(CommonTiramisuOption):
self.subconfig.setattr(value, self.subconfig.setattr(value,
self.option_bag) self.option_bag)
@count
def _pop(self, index): def _pop(self, index):
"""pop value for a master option (only for master option)""" """pop value for a master option (only for master option)"""
self._get_option() self._get_option()
if self.option_bag.option.impl_is_symlinkoption(): if self.option_bag.option.impl_is_symlinkoption():
raise TypeError(_("can't delete a SymLinkOption")) raise TypeError(_("can't delete a SymLinkOption"))
self.config_bag.config.cfgimpl_get_values().reset_master(index, self.config_bag.context.cfgimpl_get_values().reset_master(index,
self.option_bag, self.option_bag,
self.subconfig) self.subconfig)
@count
def reset(self): def reset(self):
"""reset value for a value""" """reset value for a value"""
self._get_option() self._get_option()
self._test_slave_index() self._test_slave_index()
#self.config_bag.config.delattr(self.option_bag)
self.subconfig.delattr(self.option_bag) self.subconfig.delattr(self.option_bag)
@count
def _len_master(self): def _len_master(self):
"""length of master option (only for slave option)""" """length of master option (only for slave option)"""
option = self._get_option() option = self._get_option()
@ -561,7 +469,6 @@ class TiramisuOptionValue(CommonTiramisuOption):
self._length = self.subconfig.cfgimpl_get_length() self._length = self.subconfig.cfgimpl_get_length()
return self._length return self._length
@count
def _len_slave(self): def _len_slave(self):
"""length of slave option (only for slave option)""" """length of slave option (only for slave option)"""
option = self._get_option() option = self._get_option()
@ -582,7 +489,6 @@ class TiramisuOptionValue(CommonTiramisuOption):
return self._len_master return self._len_master
raise APIError(_('{} is unknown').format(name)) raise APIError(_('{} is unknown').format(name))
@count
def _list(self): def _list(self):
"""all values available for an option (only for choiceoption)""" """all values available for an option (only for choiceoption)"""
self._get_option() self._get_option()
@ -630,7 +536,6 @@ class TiramisuOption(CommonTiramisu):
return getattr(self, '_' + subfunc) return getattr(self, '_' + subfunc)
raise APIError(_('please specify a valid sub function ({})').format(subfunc)) raise APIError(_('please specify a valid sub function ({})').format(subfunc))
@count
def _make_dict(self, def _make_dict(self,
flatten=False, flatten=False,
withvalue=undefined, withvalue=undefined,
@ -638,7 +543,7 @@ class TiramisuOption(CommonTiramisu):
fullpath=False): fullpath=False):
"""return dict with path as key and value for an optiondescription (only for optiondescription)""" """return dict with path as key and value for an optiondescription (only for optiondescription)"""
self._get_option() self._get_option()
return self.config_bag.config.get_subconfig(self._path, return self.config_bag.context.get_subconfig(self._path,
self.option_bag).make_dict(config_bag=self.config_bag, self.option_bag).make_dict(config_bag=self.config_bag,
flatten=flatten, flatten=flatten,
fullpath=fullpath, fullpath=fullpath,
@ -653,12 +558,12 @@ class TiramisuOption(CommonTiramisu):
"""find an option by name (only for optiondescription)""" """find an option by name (only for optiondescription)"""
if not first: if not first:
ret = [] ret = []
for path in self.config_bag.config.find(byname=name, for path in self.config_bag.context.find(byname=name,
byvalue=value, byvalue=value,
bytype=type, bytype=type,
_subpath=self._path, _subpath=self._path,
config_bag=self.config_bag): config_bag=self.config_bag):
subconfig, name = self.config_bag.config.cfgimpl_get_home_by_path(path, subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag) self.config_bag)
t_option = TiramisuOption(name, t_option = TiramisuOption(name,
path, path,
@ -670,7 +575,6 @@ class TiramisuOption(CommonTiramisu):
ret.append(t_option) ret.append(t_option)
return ret return ret
@count
def _get(self, name): def _get(self, name):
self._get_option() self._get_option()
current_option = self.option_bag.option.impl_getchild(name, current_option = self.option_bag.option.impl_getchild(name,
@ -694,12 +598,10 @@ class TiramisuOption(CommonTiramisu):
self.config_bag, self.config_bag,
option_bag) option_bag)
@count
def _group_type(self): def _group_type(self):
"""get type for an optiondescription (only for optiondescription)""" """get type for an optiondescription (only for optiondescription)"""
return self._get_option().impl_get_group_type() return self._get_option().impl_get_group_type()
@count
def _list(self, def _list(self,
type='all', type='all',
group_type=None): group_type=None):
@ -763,28 +665,24 @@ class TiramisuContext(TiramisuHelp):
class TiramisuContextInformation(TiramisuContext): class TiramisuContextInformation(TiramisuContext):
"""manage configuration informations""" """manage configuration informations"""
@count
def get(self, name, default=undefined): def get(self, name, default=undefined):
"""get information for a key name""" """get information for a key name"""
return self.config_bag.config.impl_get_information(name, default) return self.config_bag.context.impl_get_information(name, default)
@count
def set(self, name, value): def set(self, name, value):
"""set information for a key name""" """set information for a key name"""
self.config_bag.config.impl_set_information(name, value) self.config_bag.context.impl_set_information(name, value)
@count
def reset(self, name): def reset(self, name):
"""remove information for a key name""" """remove information for a key name"""
self.config_bag.config.impl_del_information(name) self.config_bag.context.impl_del_information(name)
class TiramisuContextValue(TiramisuContext): class TiramisuContextValue(TiramisuContext):
"""manager value""" """manager value"""
@count
def mandatory_warnings(self): def mandatory_warnings(self):
"""return path of options with mandatory property without any value""" """return path of options with mandatory property without any value"""
return self.config_bag.config.cfgimpl_get_values().mandatory_warnings(self.config_bag) return self.config_bag.context.cfgimpl_get_values().mandatory_warnings(self.config_bag)
def set(self, def set(self,
path: str, path: str,
@ -804,40 +702,35 @@ class TiramisuContextValue(TiramisuContext):
kwargs['force_default_if_same'] = force_default_if_same kwargs['force_default_if_same'] = force_default_if_same
if force_dont_change_value is not undefined: if force_dont_change_value is not undefined:
kwargs['force_dont_change_value'] = force_dont_change_value kwargs['force_dont_change_value'] = force_dont_change_value
return self.config_bag.config.set_value(path, return self.config_bag.context.set_value(path,
index, index,
value, value,
self.config_bag, self.config_bag,
**kwargs) **kwargs)
@count
def reset(self, def reset(self,
path): path):
"""reset value for a GroupConfig or a MetaConfig""" """reset value for a GroupConfig or a MetaConfig"""
self.config_bag.config.reset(path, self.config_bag.context.reset(path,
self.config_bag) self.config_bag)
@count
def exportation(self): def exportation(self):
"""export all values""" """export all values"""
return self.config_bag.config.cfgimpl_get_values()._p_.exportation() return self.config_bag.context.cfgimpl_get_values()._p_.exportation()
@count
def importation(self, values): def importation(self, values):
"""import values""" """import values"""
self.config_bag.config.cfgimpl_get_values()._p_.importation(values) self.config_bag.context.cfgimpl_get_values()._p_.importation(values)
self.config_bag.config.cfgimpl_reset_cache(None, None) self.config_bag.context.cfgimpl_reset_cache(None, None)
class TiramisuContextOwner(TiramisuContext): class TiramisuContextOwner(TiramisuContext):
"""manager value""" """manager value"""
@count
def get(self): def get(self):
"""get default owner""" """get default owner"""
return self.config_bag.config.cfgimpl_get_settings().getowner() return self.config_bag.context.cfgimpl_get_settings().getowner()
@count
def set(self, owner): def set(self, owner):
"""set default owner""" """set default owner"""
try: try:
@ -845,26 +738,24 @@ class TiramisuContextOwner(TiramisuContext):
except AttributeError: except AttributeError:
owners.addowner(owner) owners.addowner(owner)
obj_owner = getattr(owners, owner) obj_owner = getattr(owners, owner)
self.config_bag.config.cfgimpl_get_settings().setowner(obj_owner) self.config_bag.context.cfgimpl_get_settings().setowner(obj_owner)
class TiramisuContextProperty(TiramisuContext): class TiramisuContextProperty(TiramisuContext):
"""manage configuration properties""" """manage configuration properties"""
@count
def read_only(self): def read_only(self):
"""set configuration to read only mode""" """set configuration to read only mode"""
settings = self.config_bag.config.cfgimpl_get_settings() settings = self.config_bag.context.cfgimpl_get_settings()
settings.read_only() settings.read_only()
try: try:
del self.config_bag.setting_properties del self.config_bag.setting_properties
except AttributeError: except AttributeError:
pass pass
@count
def read_write(self): def read_write(self):
"""set configuration to read and write mode""" """set configuration to read and write mode"""
settings = self.config_bag.config.cfgimpl_get_settings() settings = self.config_bag.context.cfgimpl_get_settings()
settings.read_write() settings.read_write()
# #FIXME ? # #FIXME ?
settings.set_context_permissive(frozenset(['hidden'])) settings.set_context_permissive(frozenset(['hidden']))
@ -874,14 +765,12 @@ class TiramisuContextProperty(TiramisuContext):
pass pass
#/FIXME ? #/FIXME ?
@count
def add(self, prop): def add(self, prop):
"""add a configuration property""" """add a configuration property"""
props = self.get() props = self.get()
props.add(prop) props.add(prop)
self.set(frozenset(props)) self.set(frozenset(props))
@count
def pop(self, prop): def pop(self, prop):
"""remove a configuration property""" """remove a configuration property"""
props = self.get() props = self.get()
@ -889,57 +778,48 @@ class TiramisuContextProperty(TiramisuContext):
props.remove(prop) props.remove(prop)
self.set(frozenset(props)) self.set(frozenset(props))
@count
def get(self): def get(self):
"""get all configuration properties""" """get all configuration properties"""
return set(self.config_bag.setting_properties) return set(self.config_bag.setting_properties)
@count
def set(self, props): def set(self, props):
"""personalise configuration properties""" """personalise configuration properties"""
self.config_bag.config.cfgimpl_get_settings().set_context_properties(props) self.config_bag.context.cfgimpl_get_settings().set_context_properties(props)
@count
def reset(self): def reset(self):
"""remove configuration properties""" """remove configuration properties"""
self.config_bag.config.cfgimpl_get_settings().reset(None) self.config_bag.context.cfgimpl_get_settings().reset(None)
@count
def exportation(self): def exportation(self):
"""export configuration properties""" """export configuration properties"""
return self.config_bag.config.cfgimpl_get_settings()._p_.exportation() return self.config_bag.context.cfgimpl_get_settings()._p_.exportation()
@count
def importation(self, properties): def importation(self, properties):
"""import configuration properties""" """import configuration properties"""
self.config_bag.config.cfgimpl_get_settings()._p_.importation(properties) self.config_bag.context.cfgimpl_get_settings()._p_.importation(properties)
self.config_bag.config.cfgimpl_reset_cache(None, self.config_bag.context.cfgimpl_reset_cache(None,
None) None)
class TiramisuContextPermissive(TiramisuContext): class TiramisuContextPermissive(TiramisuContext):
"""manage configuration permissives""" """manage configuration permissives"""
@count
def get(self): def get(self):
"""get configuration permissives""" """get configuration permissives"""
return self.config_bag.config.cfgimpl_get_settings().get_context_permissive() return self.config_bag.context.cfgimpl_get_settings().get_context_permissive()
@count
def set(self, permissives): def set(self, permissives):
"""set configuration permissives""" """set configuration permissives"""
self.config_bag.config.cfgimpl_get_settings().set_context_permissive(permissives) self.config_bag.context.cfgimpl_get_settings().set_context_permissive(permissives)
@count
def exportation(self): def exportation(self):
"""export configuration permissives""" """export configuration permissives"""
return self.config_bag.config.cfgimpl_get_settings()._pp_.exportation() return self.config_bag.context.cfgimpl_get_settings()._pp_.exportation()
@count
def importation(self, permissives): def importation(self, permissives):
"""import configuration permissives""" """import configuration permissives"""
self.config_bag.config.cfgimpl_get_settings()._pp_.importation(permissives) self.config_bag.context.cfgimpl_get_settings()._pp_.importation(permissives)
self.config_bag.config.cfgimpl_reset_cache(None, self.config_bag.context.cfgimpl_reset_cache(None,
None) None)
@ -947,7 +827,6 @@ class TiramisuContextPermissive(TiramisuContext):
class TiramisuContextOption(TiramisuContext): class TiramisuContextOption(TiramisuContext):
"""manage option""" """manage option"""
@count
def find(self, def find(self,
name, name,
value=undefined, value=undefined,
@ -956,12 +835,12 @@ class TiramisuContextOption(TiramisuContext):
"""find an option by name""" """find an option by name"""
if not first: if not first:
ret = [] ret = []
for path in self.config_bag.config.find(byname=name, for path in self.config_bag.context.find(byname=name,
byvalue=value, byvalue=value,
bytype=type, bytype=type,
#_subpath=self._path, #_subpath=self._path,
config_bag=self.config_bag): config_bag=self.config_bag):
subconfig, name = self.config_bag.config.cfgimpl_get_home_by_path(path, subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag) self.config_bag)
t_option = TiramisuOption(name, t_option = TiramisuOption(name,
path, path,
@ -973,31 +852,28 @@ class TiramisuContextOption(TiramisuContext):
ret.append(t_option) ret.append(t_option)
return ret return ret
@count
def get(self, name): def get(self, name):
option = self.config_bag.config.cfgimpl_get_description().impl_getchild(name, option = self.config_bag.context.cfgimpl_get_description().impl_getchild(name,
self.config_bag, self.config_bag,
self.config_bag.config) self.config_bag.context)
return TiramisuOption(name, return TiramisuOption(name,
name, name,
None, None,
self.config_bag.config, self.config_bag.context,
self.config_bag) self.config_bag)
@count
def make_dict(self, def make_dict(self,
flatten=False, flatten=False,
withvalue=undefined, withvalue=undefined,
withoption=None, withoption=None,
fullpath=False): fullpath=False):
"""return dict with path as key and value""" """return dict with path as key and value"""
return self.config_bag.config.make_dict(self.config_bag, return self.config_bag.context.make_dict(self.config_bag,
flatten=flatten, flatten=flatten,
fullpath=fullpath, fullpath=fullpath,
withoption=withoption, withoption=withoption,
withvalue=withvalue) withvalue=withvalue)
@count
def list(self, def list(self,
type='all', type='all',
group_type=None, group_type=None,
@ -1011,7 +887,7 @@ class TiramisuContextOption(TiramisuContext):
name, name,
None, None,
self.config_bag) self.config_bag)
self.config_bag.config.getattr(name, self.config_bag.context.getattr(name,
option_bag) option_bag)
if type not in ('all', 'optiondescription'): if type not in ('all', 'optiondescription'):
raise APIError(_('unknown list type {}').format(type)) raise APIError(_('unknown list type {}').format(type))
@ -1024,13 +900,13 @@ class TiramisuContextOption(TiramisuContext):
raise APIError(_('recursive with group_type is not implemented yet')) raise APIError(_('recursive with group_type is not implemented yet'))
if not self.config_bag.force_unrestraint: if not self.config_bag.force_unrestraint:
raise APIError(_('not implemented yet')) raise APIError(_('not implemented yet'))
for option in self.config_bag.config.cfgimpl_get_description()._cache_paths[1]: for option in self.config_bag.context.cfgimpl_get_description()._cache_paths[1]:
if type == 'optiondescription' and not isinstance(option, OptionDescription): if type == 'optiondescription' and not isinstance(option, OptionDescription):
continue continue
yield option yield option
else: else:
option = self.config_bag.config.cfgimpl_get_description() option = self.config_bag.context.cfgimpl_get_description()
for opt in option.impl_getchildren(self.config_bag): for opt in option.impl_getchildren(self.config_bag):
try: try:
subsubconfig = _filter(opt) subsubconfig = _filter(opt)
@ -1045,9 +921,9 @@ class TiramisuContextOption(TiramisuContext):
continue continue
name = opt.impl_getname() name = opt.impl_getname()
yield TiramisuOption(name, yield TiramisuOption(name,
self.config_bag.config._get_subpath(name), self.config_bag.context._get_subpath(name),
None, None,
self.config_bag.config, self.config_bag.context,
self.config_bag) self.config_bag)
@ -1059,7 +935,7 @@ class TiramisuContextConfig(TiramisuContext):
first: bool=False): first: bool=False):
"""find a path from option name and optionnaly a value to MetaConfig or GroupConfig""" """find a path from option name and optionnaly a value to MetaConfig or GroupConfig"""
if first: if first:
return self.config_bag.config.find_firsts(byname=name, return self.config_bag.context.find_firsts(byname=name,
byvalue=value, byvalue=value,
config_bag=self.config_bag) config_bag=self.config_bag)
else: else:
@ -1088,26 +964,26 @@ class TiramisuAPI(TiramisuHelp):
else: else:
config = self._config config = self._config
force = None force = None
config_bag = ConfigBag(config=config, config_bag = ConfigBag(context=config,
force_permissive=True) force_permissive=True)
if force is not None: if force is not None:
config_bag.force_unrestraint = force config_bag.force_unrestraint = force
return TiramisuAPI(config_bag) return TiramisuAPI(config_bag)
elif subfunc == 'unrestraint': elif subfunc == 'unrestraint':
if isinstance(self._config, ConfigBag): if isinstance(self._config, ConfigBag):
config = self._config.config config = self._config.context
force = self._config.force_permissive force = self._config.force_permissive
else: else:
config = self._config config = self._config
force = None force = None
config_bag = ConfigBag(config=config, config_bag = ConfigBag(context=config,
force_unrestraint=True) force_unrestraint=True)
if force is not None: if force is not None:
config_bag.force_permissive = force config_bag.force_permissive = force
return TiramisuAPI(config_bag) return TiramisuAPI(config_bag)
elif subfunc in self.registers: elif subfunc in self.registers:
if not isinstance(self._config, ConfigBag): if not isinstance(self._config, ConfigBag):
config_bag = ConfigBag(config=self._config) config_bag = ConfigBag(context=self._config)
else: else:
config_bag = self._config config_bag = self._config
return self.registers[subfunc](config_bag) return self.registers[subfunc](config_bag)
@ -1122,10 +998,10 @@ class TiramisuDispatcherConfig(TiramisuDispatcher, TiramisuContextConfig):
if path is None: if path is None:
return TiramisuAPI(self.config_bag) return TiramisuAPI(self.config_bag)
spaths = path.split('.') spaths = path.split('.')
config = self.config_bag.config config = self.config_bag.context
for spath in spaths: for spath in spaths:
config = config.getconfig(spath) config = config.getconfig(spath)
config_bag = ConfigBag(config=config, config_bag = ConfigBag(context=config,
force_unrestraint=self.config_bag.force_unrestraint, force_unrestraint=self.config_bag.force_unrestraint,
force_permissive=self.config_bag.force_permissive) force_permissive=self.config_bag.force_permissive)
return TiramisuAPI(config_bag) return TiramisuAPI(config_bag)
@ -1137,7 +1013,7 @@ class TiramisuDispatcherOption(TiramisuDispatcher, TiramisuContextOption):
path: str, path: str,
index: Optional[int]=None) -> TiramisuOption: index: Optional[int]=None) -> TiramisuOption:
"""select a option (index only for slave option)""" """select a option (index only for slave option)"""
subconfig, name = self.config_bag.config.cfgimpl_get_home_by_path(path, subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag) self.config_bag)
return TiramisuOption(name, return TiramisuOption(name,
path, path,
@ -1146,7 +1022,6 @@ class TiramisuDispatcherOption(TiramisuDispatcher, TiramisuContextOption):
self.config_bag) self.config_bag)
@count
def getapi(config: Union[Config, GroupConfig, MetaConfig]): def getapi(config: Union[Config, GroupConfig, MetaConfig]):
"""instanciate TiramisuAPI """instanciate TiramisuAPI

View File

@ -73,16 +73,14 @@ def manager_callback(callbk: Union[ParamOption, ParamValue],
(not opt.impl_is_master_slaves('slave') or index is None): (not opt.impl_is_master_slaves('slave') or index is None):
return orig_value return orig_value
# don't validate if option is option that we tried to validate # don't validate if option is option that we tried to validate
config_bag = ConfigBag(config=option_bag.config_bag.config, config_bag = option_bag.config_bag.copy()
_setting_properties=option_bag.config_bag._setting_properties, config_bag.force_permissive = True
force_permissive=True,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=option_bag.config_bag._validate)
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(opt, soption_bag.set_option(opt,
path, path,
index_, index_,
config_bag) config_bag)
if option_bag.fromconsistency:
soption_bag.fromconsistency = option_bag.fromconsistency.copy() soption_bag.fromconsistency = option_bag.fromconsistency.copy()
if opt == option: if opt == option:
soption_bag.config_bag.force_unrestraint = True soption_bag.config_bag.force_unrestraint = True

View File

@ -78,11 +78,8 @@ class SubConfig(object):
master = descr.getmaster() master = descr.getmaster()
masterpath = master.impl_getname() masterpath = master.impl_getname()
full_masterpath = self._get_subpath(masterpath) full_masterpath = self._get_subpath(masterpath)
cconfig_bag = ConfigBag(config=config_bag.config, cconfig_bag = config_bag.copy()
_setting_properties=config_bag._setting_properties, cconfig_bag.validate = False
force_permissive=config_bag.force_permissive,
force_unrestraint=config_bag.force_unrestraint,
_validate=False)
moption_bag = OptionBag() moption_bag = OptionBag()
moption_bag.set_option(master, moption_bag.set_option(master,
full_masterpath, full_masterpath,
@ -1033,11 +1030,8 @@ class MetaConfig(GroupConfig):
def reset(self, def reset(self,
path, path,
config_bag): config_bag):
rconfig_bag = ConfigBag(config=config_bag.config, rconfig_bag = config_bag.copy()
_setting_properties=config_bag._setting_properties, rconfig_bag.validate = False
force_permissive=config_bag.force_permissive,
force_unrestraint=config_bag.force_unrestraint,
_validate=False)
subconfig, name = self.cfgimpl_get_home_by_path(path, subconfig, name = self.cfgimpl_get_home_by_path(path,
config_bag) config_bag)
option = subconfig.cfgimpl_get_description().impl_getchild(name, option = subconfig.cfgimpl_get_description().impl_getchild(name,

View File

@ -94,7 +94,7 @@ class ChoiceOption(Option):
if option_bag.config_bag == undefined: if option_bag.config_bag == undefined:
config = undefined config = undefined
else: else:
config = option_bag.config_bag.config config = option_bag.config_bag.context
values = carry_out_calculation(current_opt, values = carry_out_calculation(current_opt,
context=config, context=config,
callback=values, callback=values,

View File

@ -75,7 +75,7 @@ class DynOptionDescription(OptionDescription):
option_bag): option_bag):
callback, callback_params = self.impl_get_callback() callback, callback_params = self.impl_get_callback()
values = carry_out_calculation(self, values = carry_out_calculation(self,
option_bag.config_bag.config, option_bag.config_bag.context,
callback, callback,
callback_params, callback_params,
None, None,
@ -93,7 +93,7 @@ class DynOptionDescription(OptionDescription):
return values return values
def get_syndynoptiondescriptions(self, option_bag): def get_syndynoptiondescriptions(self, option_bag):
subpath = self.impl_getpath(option_bag.config_bag.config).rsplit('.', 1)[0] subpath = self.impl_getpath(option_bag.config_bag.context).rsplit('.', 1)[0]
for suffix in self._impl_get_suffixes(option_bag): for suffix in self._impl_get_suffixes(option_bag):
yield SynDynOptionDescription(self, yield SynDynOptionDescription(self,
subpath, subpath,

View File

@ -24,7 +24,7 @@ from itertools import chain
from ..i18n import _ from ..i18n import _
from ..setting import groups, undefined, OptionBag, ConfigBag from ..setting import groups, undefined, OptionBag
from .optiondescription import OptionDescription from .optiondescription import OptionDescription
from .option import Option from .option import Option
from ..error import SlaveError, PropertiesOptionError from ..error import SlaveError, PropertiesOptionError
@ -107,11 +107,8 @@ class MasterSlaves(OptionDescription):
option_bag, option_bag,
_commit=True): _commit=True):
config_bag = ConfigBag(config=option_bag.config_bag.config, config_bag = option_bag.config_bag.copy()
_setting_properties=option_bag.config_bag._setting_properties, config_bag.validate = False
force_permissive=option_bag.config_bag.force_permissive,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=False)
for slave in self.getslaves(): for slave in self.getslaves():
slave_path = slave.impl_getpath(values._getcontext()) slave_path = slave.impl_getpath(values._getcontext())
soption_bag = OptionBag() soption_bag = OptionBag()
@ -131,11 +128,8 @@ class MasterSlaves(OptionDescription):
context = values._getcontext() context = values._getcontext()
if slaves is undefined: if slaves is undefined:
slaves = self.getslaves() slaves = self.getslaves()
config_bag = ConfigBag(config=option_bag.config_bag.config, config_bag = option_bag.config_bag.copy()
_setting_properties=None, config_bag.validate = False
force_permissive=option_bag.config_bag.force_permissive,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=False)
for slave in slaves: for slave in slaves:
slave_path = slave.impl_getpath(context) slave_path = slave.impl_getpath(context)
slavelen = values._p_.get_max_length(slave_path) slavelen = values._p_.get_max_length(slave_path)
@ -145,7 +139,7 @@ class MasterSlaves(OptionDescription):
index, index,
config_bag) config_bag)
# do not check force_default_on_freeze # do not check force_default_on_freeze
soption_bag.properties = {} soption_bag.properties = set()
if not values.is_default_owner(soption_bag, if not values.is_default_owner(soption_bag,
validate_meta=False): validate_meta=False):
if slavelen > index: if slavelen > index:

View File

@ -25,7 +25,7 @@ import weakref
from .baseoption import OnlyOption, submulti, STATIC_TUPLE from .baseoption import OnlyOption, submulti, STATIC_TUPLE
from .symlinkoption import DynSymLinkOption from .symlinkoption import DynSymLinkOption
from ..i18n import _ from ..i18n import _
from ..setting import log, undefined, debug, OptionBag, ConfigBag from ..setting import log, undefined, debug, OptionBag
from ..autolib import carry_out_calculation from ..autolib import carry_out_calculation
from ..error import (ConfigError, ValueWarning, PropertiesOptionError, from ..error import (ConfigError, ValueWarning, PropertiesOptionError,
display_list) display_list)
@ -468,11 +468,8 @@ class Option(OnlyOption):
if option_bag.config_bag is undefined: if option_bag.config_bag is undefined:
cconfig_bag = undefined cconfig_bag = undefined
elif option_bag.config_bag.force_permissive != True: elif option_bag.config_bag.force_permissive != True:
cconfig_bag = ConfigBag(config=option_bag.config_bag.config, cconfig_bag = option_bag.config_bag.copy()
_setting_properties=option_bag.config_bag._setting_properties, cconfig_bag.force_permissive = True
force_permissive=True,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=option_bag.config_bag._validate)
else: else:
cconfig_bag = option_bag.config_bag cconfig_bag = option_bag.config_bag
for cons_id, func, all_cons_opts, params in consistencies: for cons_id, func, all_cons_opts, params in consistencies:

View File

@ -173,7 +173,7 @@ class CacheOptionDescription(BaseOption):
'"force_store_value" property').format( '"force_store_value" property').format(
option.impl_get_display_name())) option.impl_get_display_name()))
if not values._p_.hasvalue(subpath): if not values._p_.hasvalue(subpath):
config_bag = ConfigBag(config=context) config_bag = ConfigBag(context=context)
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(option, option_bag.set_option(option,
subpath, subpath,
@ -233,7 +233,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
rootpath = self.impl_get_path_by_opt(dynopt) rootpath = self.impl_get_path_by_opt(dynopt)
ori_index = len(rootpath) + 1 ori_index = len(rootpath) + 1
subpaths = [rootpath] + option.impl_getpath( subpaths = [rootpath] + option.impl_getpath(
option_bag.config_bag.config)[ori_index:].split('.')[:-1] option_bag.config_bag.context)[ori_index:].split('.')[:-1]
for suffix in dynopt._impl_get_suffixes(option_bag): for suffix in dynopt._impl_get_suffixes(option_bag):
subpath = '.'.join([subp + suffix for subp in subpaths]) subpath = '.'.join([subp + suffix for subp in subpaths])
if isinstance(option, OnlyOption): if isinstance(option, OnlyOption):
@ -268,7 +268,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
config_bag) config_bag)
for doption in self.build_dynoptions(option_bag): for doption in self.build_dynoptions(option_bag):
if byname == doption.impl_getname(): if byname == doption.impl_getname():
dpath = doption.impl_getpath(config_bag.config) dpath = doption.impl_getpath(config_bag.context)
return (dpath, doption) return (dpath, doption)
elif byname == name: elif byname == name:
return (path, option) return (path, option)
@ -321,13 +321,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
subpath = None subpath = None
for child in self._impl_st_getchildren(): for child in self._impl_st_getchildren():
if dyn and child.impl_is_dynoptiondescription(): if dyn and child.impl_is_dynoptiondescription():
if config_bag.config is None: # pragma: no cover if config_bag.context is None: # pragma: no cover
raise ConfigError(_('need context')) raise ConfigError(_('need context'))
if subpath is None: if subpath is None:
if config_bag.config.cfgimpl_get_description() == self: if config_bag.context.cfgimpl_get_description() == self:
subpath = '' subpath = ''
else: else:
subpath = self.impl_getpath(config_bag.config) subpath = self.impl_getpath(config_bag.context)
option_bag = OptionBag() option_bag = OptionBag()
option_bag.set_option(child, option_bag.set_option(child,
subpath, subpath,

View File

@ -107,7 +107,7 @@ class DynSymLinkOption(object):
option_bag, option_bag,
context=undefined, context=undefined,
check_error=True): check_error=True):
context = option_bag.config_bag.config context = option_bag.config_bag.context
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(self._opt, soption_bag.set_option(self._opt,
self.impl_getpath(context), self.impl_getpath(context),

View File

@ -67,7 +67,7 @@ class SynDynOptionDescription(object):
config_bag, config_bag,
dyn=True): dyn=True):
children = [] children = []
subpath = self.impl_getpath(config_bag.config) subpath = self.impl_getpath(config_bag.context)
for child in self._opt.impl_getchildren(config_bag): for child in self._opt.impl_getchildren(config_bag):
yield(self._opt._impl_get_dynchild(child, yield(self._opt._impl_get_dynchild(child,
self._suffix, self._suffix,

View File

@ -140,7 +140,7 @@ class OptionBag:
if self.option != None: if self.option != None:
raise Exception('hu?') raise Exception('hu?')
if path is None: if path is None:
path = config_bag.config.cfgimpl_get_description().impl_get_path_by_opt(option) path = config_bag.context.cfgimpl_get_description().impl_get_path_by_opt(option)
self.path = path self.path = path
self.index = index self.index = index
self.option = option self.option = option
@ -148,7 +148,7 @@ class OptionBag:
def __getattr__(self, key): def __getattr__(self, key):
if key == 'properties': if key == 'properties':
settings = self.config_bag.config.cfgimpl_get_settings() settings = self.config_bag.context.cfgimpl_get_settings()
self.properties = settings.getproperties(self, apply_requires=self.apply_requires) self.properties = settings.getproperties(self, apply_requires=self.apply_requires)
return self.properties return self.properties
elif key == 'ori_option': elif key == 'ori_option':
@ -159,16 +159,16 @@ class OptionBag:
class ConfigBag: class ConfigBag:
__slots__ = ('config', # link to the current config (context) __slots__ = ('context', # link to the current config (context)
'_setting_properties', # properties for current config '_setting_properties', # properties for current config
'force_permissive', # force permissive 'force_permissive', # force permissive
'force_unrestraint', # do not validate properties 'force_unrestraint', # do not validate properties
'_validate', # validate '_validate', # validate
) )
def __init__(self, config, **kwargs): def __init__(self, context, **kwargs):
self.force_permissive = False self.force_permissive = False
self.force_unrestraint = False self.force_unrestraint = False
self.config = config self.context = context
self._validate = True self._validate = True
for key, value in kwargs.items(): for key, value in kwargs.items():
setattr(self, key, value) setattr(self, key, value)
@ -185,7 +185,7 @@ class ConfigBag:
return None return None
return self._setting_properties return self._setting_properties
if key == '_setting_properties': if key == '_setting_properties':
self._setting_properties = self.config.cfgimpl_get_settings().get_context_properties() self._setting_properties = self.context.cfgimpl_get_settings().get_context_properties()
if self._validate is False: if self._validate is False:
self._setting_properties = self._setting_properties - {'validator'} self._setting_properties = self._setting_properties - {'validator'}
return self._setting_properties return self._setting_properties
@ -514,17 +514,13 @@ class Settings(object):
idx = option_bag.index idx = option_bag.index
elif option.impl_is_multi(): elif option.impl_is_multi():
is_indexed = True is_indexed = True
config_bag = ConfigBag(config=option_bag.config_bag.config, config_bag = option_bag.config_bag.copy()
_setting_properties=option_bag.config_bag._setting_properties, config_bag.force_permissive = True
force_permissive=True,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=option_bag.config_bag._validate)
soption_bag = OptionBag() soption_bag = OptionBag()
soption_bag.set_option(option, soption_bag.set_option(option,
reqpath, reqpath,
idx, idx,
config_bag) config_bag)
soption_bag.config_bag.force_permissive = True
if option_bag.option == option: if option_bag.option == option:
soption_bag.config_bag.force_unrestraint = True soption_bag.config_bag.force_unrestraint = True
soption_bag.config_bag.validate = False soption_bag.config_bag.validate = False
@ -718,9 +714,8 @@ class Settings(object):
was present was present
""" """
# calc properties # calc properties
self_properties = option_bag.properties
config_bag = option_bag.config_bag config_bag = option_bag.config_bag
properties = self_properties & config_bag.setting_properties - {'frozen', 'mandatory', 'empty'} properties = option_bag.properties & config_bag.setting_properties - {'frozen', 'mandatory', 'empty'}
# remove permissive properties # remove permissive properties
if (config_bag.force_permissive is True or \ if (config_bag.force_permissive is True or \

View File

@ -647,7 +647,7 @@ class Values(object):
od_setting_properties = config_bag.setting_properties - {'mandatory', 'empty'} od_setting_properties = config_bag.setting_properties - {'mandatory', 'empty'}
setting_properties = set(config_bag.setting_properties) - {'warnings'} setting_properties = set(config_bag.setting_properties) - {'warnings'}
setting_properties.update(['mandatory', 'empty']) setting_properties.update(['mandatory', 'empty'])
config_bag = ConfigBag(config=config_bag.config) config_bag = ConfigBag(context=config_bag.context)
config_bag._setting_properties = frozenset(setting_properties) config_bag._setting_properties = frozenset(setting_properties)
config_bag.force_permissive = True config_bag.force_permissive = True