From 6a3b7102b502ab59ae483eb285ee43319c17d934 Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 6 Feb 2013 14:59:24 +0100 Subject: [PATCH] adds a freeze_everything possibility --- test/test_option_type.py | 10 ++++++++++ tiramisu/config.py | 1 - tiramisu/option.py | 4 ++++ tiramisu/setting.py | 27 ++++++++++++++++++++++----- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/test/test_option_type.py b/test/test_option_type.py index bba0845..2525347 100644 --- a/test/test_option_type.py +++ b/test/test_option_type.py @@ -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() diff --git a/tiramisu/config.py b/tiramisu/config.py index 2472775..fb112e4 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -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): diff --git a/tiramisu/option.py b/tiramisu/option.py index 41ab171..2f1f356 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -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)) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 3798ba7..d1dcb6e 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -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')