adds a freeze_everything possibility
authorgwen <gremond@cadoles.com>
Wed, 6 Feb 2013 13:59:24 +0000 (14:59 +0100)
committergwen <gremond@cadoles.com>
Wed, 6 Feb 2013 13:59:24 +0000 (14:59 +0100)
test/test_option_type.py
tiramisu/config.py
tiramisu/option.py
tiramisu/setting.py

index bba0845..2525347 100644 (file)
@@ -61,6 +61,16 @@ def make_description_freeze():
                                            intoption, boolop])
     return descr
 
                                            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()
 def test_freeze_one_option():
     "freeze an option "
     descr = make_description_freeze()
index 2472775..fb112e4 100644 (file)
@@ -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()
         "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):
         self._cfgimpl_build()
 
     def _validate_duplicates(self, children):
index 41ab171..2f1f356 100644 (file)
@@ -366,6 +366,10 @@ class Option(HiddenBaseType, DisabledBaseType):
         if name not in config._cfgimpl_values:
             raise AttributeError('unknown option %s' % (name))
 
         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))
         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))
index 3798ba7..d1dcb6e 100644 (file)
@@ -114,9 +114,10 @@ class Setting():
     frozen = True
     # enables validation function for options if set
     validator = False
     frozen = True
     # enables validation function for options if set
     validator = False
-   # generic owner
+    # generic owner
     owner = owners.user
     owner = owners.user
-
+    # in order to freeze everything, not **only** the frozen options
+    everything_frozen = False
     #____________________________________________________________
     # properties methods
     def has_properties(self):
     #____________________________________________________________
     # 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
         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"
     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
         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"
 
     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')
         self.freeze()
         self.enable_property('hidden')
         self.enable_property('disabled')