adds a freeze_everything possibility
This commit is contained in:
parent
d00a623fc1
commit
6a3b7102b5
4 changed files with 36 additions and 6 deletions
|
@ -61,6 +61,16 @@ def make_description_freeze():
|
|||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
def test_freeze_whole_config():
|
||||
descr = make_description_freeze()
|
||||
conf = Config(descr)
|
||||
settings.freeze_everything()
|
||||
assert conf.gc.dummy == False
|
||||
raises(TypeError, "conf.gc.dummy = True")
|
||||
settings.un_freeze_everything()
|
||||
conf.gc.dummy = True
|
||||
assert conf.gc.dummy == True
|
||||
|
||||
def test_freeze_one_option():
|
||||
"freeze an option "
|
||||
descr = make_description_freeze()
|
||||
|
|
|
@ -49,7 +49,6 @@ class Config(object):
|
|||
"warnings are a great idea, let's make up a better use of it"
|
||||
self._cfgimpl_warnings = []
|
||||
self._cfgimpl_toplevel = self._cfgimpl_get_toplevel()
|
||||
'`freeze()` allows us to carry out this calculation again if necessary'
|
||||
self._cfgimpl_build()
|
||||
|
||||
def _validate_duplicates(self, children):
|
||||
|
|
|
@ -366,6 +366,10 @@ class Option(HiddenBaseType, DisabledBaseType):
|
|||
if name not in config._cfgimpl_values:
|
||||
raise AttributeError('unknown option %s' % (name))
|
||||
|
||||
if settings.is_frozen_for_everything():
|
||||
raise TypeError("cannot set a value to the option {} if the whole "
|
||||
"config has been frozen".format(name))
|
||||
|
||||
if settings.is_frozen() and self.is_frozen():
|
||||
raise TypeError('cannot change the value to %s for '
|
||||
'option %s this option is frozen' % (str(value), name))
|
||||
|
|
|
@ -114,9 +114,10 @@ class Setting():
|
|||
frozen = True
|
||||
# enables validation function for options if set
|
||||
validator = False
|
||||
# generic owner
|
||||
# generic owner
|
||||
owner = owners.user
|
||||
|
||||
# in order to freeze everything, not **only** the frozen options
|
||||
everything_frozen = False
|
||||
#____________________________________________________________
|
||||
# properties methods
|
||||
def has_properties(self):
|
||||
|
@ -142,11 +143,27 @@ class Setting():
|
|||
if not isinstance(permissive, list):
|
||||
raise TypeError('permissive must be a list')
|
||||
self.permissive = permissive
|
||||
#____________________________________________________________
|
||||
# complete freeze methods
|
||||
def freeze_everything(self):
|
||||
"""everything is frozen, not only the option that are tagged "frozen"
|
||||
"""
|
||||
self.everything_frozen = True
|
||||
|
||||
def un_freeze_everything(self):
|
||||
"""everything is frozen, not only the option that are tagged "frozen"
|
||||
"""
|
||||
self.everything_frozen = False
|
||||
|
||||
def is_frozen_for_everything(self):
|
||||
"""frozen for a whole config (not only the options
|
||||
that have been set to frozen)"""
|
||||
return self.everything_frozen
|
||||
#____________________________________________________________
|
||||
def read_only(self):
|
||||
"convenience method to freeze, hidde and disable"
|
||||
# FIXME LE FREEZE NE MARCHE PAS
|
||||
self.freeze()
|
||||
self.freeze_everything()
|
||||
self.freeze() # can be usefull...
|
||||
self.disable_property('hidden')
|
||||
self.enable_property('disabled')
|
||||
self.mandatory = True
|
||||
|
@ -154,7 +171,7 @@ class Setting():
|
|||
|
||||
def read_write(self):
|
||||
"convenience method to freeze, hidde and disable"
|
||||
# FIXME : POURQUOI UN FREEZE ICI ?
|
||||
self.un_freeze_everything()
|
||||
self.freeze()
|
||||
self.enable_property('hidden')
|
||||
self.enable_property('disabled')
|
||||
|
|
Loading…
Reference in a new issue