remove _getcontext in Settings
This commit is contained in:
@ -328,7 +328,8 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
apply_requires=False)
|
||||
self.settings.setproperties(self.option_bag.path,
|
||||
props | {prop},
|
||||
self.option_bag)
|
||||
self.option_bag,
|
||||
self.option_bag.config_bag.context)
|
||||
|
||||
def pop(self, prop):
|
||||
"""remove new property for an option"""
|
||||
@ -337,12 +338,14 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
apply_requires=False)
|
||||
self.settings.setproperties(self.option_bag.path,
|
||||
props - {prop},
|
||||
self.option_bag)
|
||||
self.option_bag,
|
||||
self.option_bag.config_bag.context)
|
||||
|
||||
def reset(self):
|
||||
"""reset all personalised properties"""
|
||||
option = self.option_bag.option
|
||||
self.settings.reset(self.option_bag)
|
||||
self.settings.reset(self.option_bag,
|
||||
self.option_bag.config_bag.context)
|
||||
|
||||
|
||||
class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
@ -734,7 +737,7 @@ class TiramisuContextProperty(TiramisuContext):
|
||||
def read_only(self):
|
||||
"""set configuration to read only mode"""
|
||||
settings = self.config_bag.context.cfgimpl_get_settings()
|
||||
settings.read_only()
|
||||
settings.read_only(self.config_bag.context)
|
||||
try:
|
||||
del self.config_bag.properties
|
||||
except AttributeError:
|
||||
@ -743,7 +746,7 @@ class TiramisuContextProperty(TiramisuContext):
|
||||
def read_write(self):
|
||||
"""set configuration to read and write mode"""
|
||||
settings = self.config_bag.context.cfgimpl_get_settings()
|
||||
settings.read_write()
|
||||
settings.read_write(self.config_bag.context)
|
||||
# #FIXME ?
|
||||
permissives = frozenset(settings.get_context_permissives() | frozenset(['hidden']))
|
||||
settings.set_context_permissives(permissives)
|
||||
@ -772,11 +775,15 @@ class TiramisuContextProperty(TiramisuContext):
|
||||
|
||||
def set(self, props):
|
||||
"""personalise configuration properties"""
|
||||
self.config_bag.context.cfgimpl_get_settings().set_context_properties(props)
|
||||
context = self.config_bag.context
|
||||
context.cfgimpl_get_settings().set_context_properties(props,
|
||||
context)
|
||||
|
||||
def reset(self):
|
||||
"""remove configuration properties"""
|
||||
self.config_bag.context.cfgimpl_get_settings().reset(None)
|
||||
context = self.config_bag.context
|
||||
context.cfgimpl_get_settings().reset(None,
|
||||
context)
|
||||
|
||||
def exportation(self):
|
||||
"""export configuration properties"""
|
||||
|
@ -746,13 +746,11 @@ class KernelConfig(_CommonConfig):
|
||||
raise ConfigError(_('cannot set dynoptiondescription 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,
|
||||
force_settings[0],
|
||||
self._impl_settings = Settings(force_settings[0],
|
||||
force_settings[1])
|
||||
else:
|
||||
self._impl_settings = force_settings
|
||||
self._impl_values = Values(self,
|
||||
force_values)
|
||||
self._impl_values = Values(force_values)
|
||||
else:
|
||||
properties, permissives, values, session_id = get_storages(self,
|
||||
session_id,
|
||||
@ -760,11 +758,9 @@ class KernelConfig(_CommonConfig):
|
||||
storage=storage)
|
||||
if not valid_name(session_id):
|
||||
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
|
||||
self._impl_settings = Settings(self,
|
||||
properties,
|
||||
self._impl_settings = Settings(properties,
|
||||
permissives)
|
||||
self._impl_values = Values(self,
|
||||
values)
|
||||
self._impl_values = Values(values)
|
||||
super().__init__(descr,
|
||||
weakref.ref(self),
|
||||
ConfigBag(self),
|
||||
@ -815,11 +811,9 @@ class KernelGroupConfig(_CommonConfig):
|
||||
self._impl_children = children
|
||||
|
||||
if force_settings is not None and force_values is not None:
|
||||
self._impl_settings = Settings(self,
|
||||
force_settings[0],
|
||||
self._impl_settings = Settings(force_settings[0],
|
||||
force_settings[1])
|
||||
self._impl_values = Values(self,
|
||||
force_values)
|
||||
self._impl_values = Values(force_values)
|
||||
else:
|
||||
properties, permissives, values, session_id = get_storages(self,
|
||||
session_id,
|
||||
@ -827,11 +821,9 @@ class KernelGroupConfig(_CommonConfig):
|
||||
storage=storage)
|
||||
if not valid_name(session_id):
|
||||
raise ValueError(_("invalid session ID: {0} for config").format(session_id))
|
||||
self._impl_settings = Settings(self,
|
||||
properties,
|
||||
self._impl_settings = Settings(properties,
|
||||
permissives)
|
||||
self._impl_values = Values(self,
|
||||
values)
|
||||
self._impl_values = Values(values)
|
||||
|
||||
self._impl_meta = None
|
||||
super().__init__(_descr,
|
||||
|
@ -319,9 +319,11 @@ undefined = Undefined()
|
||||
#____________________________________________________________
|
||||
class Settings(object):
|
||||
"``config.Config()``'s configuration options settings"
|
||||
__slots__ = ('context', '_owner', '_p_', '_pp_', '__weakref__')
|
||||
__slots__ = ('_owner', '_p_', '_pp_', '__weakref__')
|
||||
|
||||
def __init__(self, context, properties, permissives):
|
||||
def __init__(self,
|
||||
properties,
|
||||
permissives):
|
||||
"""
|
||||
initializer
|
||||
|
||||
@ -333,21 +335,9 @@ class Settings(object):
|
||||
"""
|
||||
# generic owner
|
||||
self._owner = owners.user
|
||||
self.context = weakref.ref(context)
|
||||
self._p_ = properties
|
||||
self._pp_ = permissives
|
||||
|
||||
def _getcontext(self):
|
||||
"""context could be None, we need to test it
|
||||
context is None only if all reference to `Config` object is deleted
|
||||
(for example we delete a `Config` and we manipulate a reference to
|
||||
old `SubConfig`, `Values`, `Multi` or `Settings`)
|
||||
"""
|
||||
context = self.context()
|
||||
if context is None: # pragma: no cover
|
||||
raise ConfigError(_('the context does not exist anymore'))
|
||||
return context
|
||||
|
||||
#____________________________________________________________
|
||||
# get properties and permissive methods
|
||||
|
||||
@ -475,7 +465,7 @@ class Settings(object):
|
||||
if not current_requires:
|
||||
return calc_properties
|
||||
|
||||
context = self._getcontext()
|
||||
context = option_bag.config_bag.context
|
||||
all_properties = None
|
||||
for requires in current_requires:
|
||||
for require in requires:
|
||||
@ -574,15 +564,18 @@ class Settings(object):
|
||||
#____________________________________________________________
|
||||
# set methods
|
||||
def set_context_properties(self,
|
||||
properties):
|
||||
properties,
|
||||
context):
|
||||
self.setproperties(None,
|
||||
properties,
|
||||
None)
|
||||
None,
|
||||
context)
|
||||
|
||||
def setproperties(self,
|
||||
path,
|
||||
properties,
|
||||
option_bag):
|
||||
option_bag,
|
||||
context):
|
||||
"""save properties for specified path
|
||||
(never save properties if same has option properties)
|
||||
"""
|
||||
@ -611,7 +604,7 @@ class Settings(object):
|
||||
self._p_.setproperties(path,
|
||||
properties)
|
||||
#values too because of slave values could have a PropertiesOptionError has value
|
||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
if option_bag is not None:
|
||||
try:
|
||||
del option_bag.properties
|
||||
@ -651,14 +644,14 @@ class Settings(object):
|
||||
' '.join(forbidden_permissives)))
|
||||
self._pp_.setpermissives(path, permissives)
|
||||
if option_bag is not None:
|
||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
||||
option_bag.config_bag.context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
#____________________________________________________________
|
||||
# reset methods
|
||||
|
||||
def reset(self,
|
||||
option_bag):
|
||||
# all_properties=False):
|
||||
option_bag,
|
||||
context):
|
||||
if option_bag is None:
|
||||
opt = None
|
||||
else:
|
||||
@ -677,7 +670,7 @@ class Settings(object):
|
||||
else:
|
||||
path = None
|
||||
self._p_.delproperties(path)
|
||||
self._getcontext().cfgimpl_reset_cache(option_bag)
|
||||
context.cfgimpl_reset_cache(option_bag)
|
||||
|
||||
#____________________________________________________________
|
||||
# validate properties
|
||||
@ -716,7 +709,7 @@ class Settings(object):
|
||||
value,
|
||||
option_bag):
|
||||
if 'mandatory' in option_bag.config_bag.properties:
|
||||
values = self._getcontext().cfgimpl_get_values()
|
||||
values = option_bag.config_bag.context.cfgimpl_get_values()
|
||||
is_mandatory = False
|
||||
if ('permissive' in option_bag.config_bag.properties) and \
|
||||
'mandatory' in option_bag.config_bag.permissives:
|
||||
@ -751,7 +744,8 @@ class Settings(object):
|
||||
|
||||
def _read(self,
|
||||
remove,
|
||||
append):
|
||||
append,
|
||||
context):
|
||||
props = self._p_.getproperties(None,
|
||||
default_properties)
|
||||
modified = False
|
||||
@ -762,17 +756,22 @@ class Settings(object):
|
||||
props = props | append
|
||||
modified = True
|
||||
if modified:
|
||||
self.set_context_properties(frozenset(props))
|
||||
self.set_context_properties(frozenset(props),
|
||||
context)
|
||||
|
||||
def read_only(self):
|
||||
def read_only(self,
|
||||
context):
|
||||
"convenience method to freeze, hide and disable"
|
||||
self._read(ro_remove,
|
||||
ro_append)
|
||||
ro_append,
|
||||
context)
|
||||
|
||||
def read_write(self):
|
||||
def read_write(self,
|
||||
context):
|
||||
"convenience method to freeze, hide and disable"
|
||||
self._read(rw_remove,
|
||||
rw_append)
|
||||
rw_append,
|
||||
context)
|
||||
|
||||
#____________________________________________________________
|
||||
# default owner methods
|
||||
|
@ -27,21 +27,17 @@ class Values(object):
|
||||
but the values are physicaly located here, in `Values`, wich is also
|
||||
responsible of a caching utility.
|
||||
"""
|
||||
__slots__ = ('context',
|
||||
'_p_',
|
||||
__slots__ = ('_p_',
|
||||
'__weakref__')
|
||||
|
||||
def __init__(self,
|
||||
context,
|
||||
storage):
|
||||
"""
|
||||
Initializes the values's dict.
|
||||
|
||||
:param context: the context is the home config's values
|
||||
:param storage: where values or owners are stored
|
||||
|
||||
"""
|
||||
self.context = weakref.ref(context)
|
||||
# store the storage
|
||||
self._p_ = storage
|
||||
|
||||
@ -436,7 +432,6 @@ class Values(object):
|
||||
_commit=True):
|
||||
|
||||
context = option_bag.config_bag.context
|
||||
setting = context.cfgimpl_get_settings()
|
||||
hasvalue = self._p_.hasvalue(option_bag.path)
|
||||
|
||||
if hasvalue and 'validator' in option_bag.config_bag.properties:
|
||||
|
Reference in New Issue
Block a user