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

View File

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

View File

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

View File

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

View File

@ -75,7 +75,7 @@ class DynOptionDescription(OptionDescription):
option_bag):
callback, callback_params = self.impl_get_callback()
values = carry_out_calculation(self,
option_bag.config_bag.config,
option_bag.config_bag.context,
callback,
callback_params,
None,
@ -93,7 +93,7 @@ class DynOptionDescription(OptionDescription):
return values
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):
yield SynDynOptionDescription(self,
subpath,

View File

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

View File

@ -25,7 +25,7 @@ import weakref
from .baseoption import OnlyOption, submulti, STATIC_TUPLE
from .symlinkoption import DynSymLinkOption
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 ..error import (ConfigError, ValueWarning, PropertiesOptionError,
display_list)
@ -468,11 +468,8 @@ class Option(OnlyOption):
if option_bag.config_bag is undefined:
cconfig_bag = undefined
elif option_bag.config_bag.force_permissive != True:
cconfig_bag = ConfigBag(config=option_bag.config_bag.config,
_setting_properties=option_bag.config_bag._setting_properties,
force_permissive=True,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=option_bag.config_bag._validate)
cconfig_bag = option_bag.config_bag.copy()
cconfig_bag.force_permissive = True
else:
cconfig_bag = option_bag.config_bag
for cons_id, func, all_cons_opts, params in consistencies:

View File

@ -173,7 +173,7 @@ class CacheOptionDescription(BaseOption):
'"force_store_value" property').format(
option.impl_get_display_name()))
if not values._p_.hasvalue(subpath):
config_bag = ConfigBag(config=context)
config_bag = ConfigBag(context=context)
option_bag = OptionBag()
option_bag.set_option(option,
subpath,
@ -233,7 +233,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
rootpath = self.impl_get_path_by_opt(dynopt)
ori_index = len(rootpath) + 1
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):
subpath = '.'.join([subp + suffix for subp in subpaths])
if isinstance(option, OnlyOption):
@ -268,7 +268,7 @@ class OptionDescriptionWalk(CacheOptionDescription):
config_bag)
for doption in self.build_dynoptions(option_bag):
if byname == doption.impl_getname():
dpath = doption.impl_getpath(config_bag.config)
dpath = doption.impl_getpath(config_bag.context)
return (dpath, doption)
elif byname == name:
return (path, option)
@ -321,13 +321,13 @@ class OptionDescriptionWalk(CacheOptionDescription):
subpath = None
for child in self._impl_st_getchildren():
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'))
if subpath is None:
if config_bag.config.cfgimpl_get_description() == self:
if config_bag.context.cfgimpl_get_description() == self:
subpath = ''
else:
subpath = self.impl_getpath(config_bag.config)
subpath = self.impl_getpath(config_bag.context)
option_bag = OptionBag()
option_bag.set_option(child,
subpath,

View File

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

View File

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

View File

@ -140,7 +140,7 @@ class OptionBag:
if self.option != None:
raise Exception('hu?')
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.index = index
self.option = option
@ -148,7 +148,7 @@ class OptionBag:
def __getattr__(self, key):
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)
return self.properties
elif key == 'ori_option':
@ -159,16 +159,16 @@ class OptionBag:
class ConfigBag:
__slots__ = ('config', # link to the current config (context)
__slots__ = ('context', # link to the current config (context)
'_setting_properties', # properties for current config
'force_permissive', # force permissive
'force_unrestraint', # do not validate properties
'_validate', # validate
)
def __init__(self, config, **kwargs):
def __init__(self, context, **kwargs):
self.force_permissive = False
self.force_unrestraint = False
self.config = config
self.context = context
self._validate = True
for key, value in kwargs.items():
setattr(self, key, value)
@ -185,7 +185,7 @@ class ConfigBag:
return None
return self._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:
self._setting_properties = self._setting_properties - {'validator'}
return self._setting_properties
@ -514,17 +514,13 @@ class Settings(object):
idx = option_bag.index
elif option.impl_is_multi():
is_indexed = True
config_bag = ConfigBag(config=option_bag.config_bag.config,
_setting_properties=option_bag.config_bag._setting_properties,
force_permissive=True,
force_unrestraint=option_bag.config_bag.force_unrestraint,
_validate=option_bag.config_bag._validate)
config_bag = option_bag.config_bag.copy()
config_bag.force_permissive = True
soption_bag = OptionBag()
soption_bag.set_option(option,
reqpath,
idx,
config_bag)
soption_bag.config_bag.force_permissive = True
if option_bag.option == option:
soption_bag.config_bag.force_unrestraint = True
soption_bag.config_bag.validate = False
@ -718,9 +714,8 @@ class Settings(object):
was present
"""
# calc properties
self_properties = option_bag.properties
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
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'}
setting_properties = set(config_bag.setting_properties) - {'warnings'}
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.force_permissive = True